HTML::TokeParser::Simple::Token - Base class for C<HTML::TokeParser::Simple>


HTML-TokeParser-Simple documentation Contained in the HTML-TokeParser-Simple distribution.

Index


Code Index:

NAME

Top

HTML::TokeParser::Simple::Token - Base class for HTML::TokeParser::Simple tokens.

SYNOPSIS

Top

 use HTML::TokeParser::Simple;
 my $p = HTML::TokeParser::Simple->new( $somefile );

 while ( my $token = $p->get_token ) {
     # This prints all text in an HTML doc (i.e., it strips the HTML)
     next unless $token->is_text;
     print $token->as_is;
 }

DESCRIPTION

Top

This is the base class for all returned tokens. It should never be instantiated directly. In fact, it will croak() if it is.

METHODS

Top

The following list of methods are provided by this class. Most of these are stub methods which must be overridden in a subclass. See HTML::TokeParser::Simple for descriptions of these methods.

* as_is
* delete_attr
* get_attr
* get_attrseq
* get_tag
* get_token0
* is_comment
* is_declaration
* is_end_tag
* is_pi
* is_process_instruction
* is_start_tag
* is_tag
* is_text
* return_attr
* return_attrseq
* return_tag
* return_text
* return_token0
* rewrite_tag
* set_attr

HTML-TokeParser-Simple documentation Contained in the HTML-TokeParser-Simple distribution.

package HTML::TokeParser::Simple::Token;

use strict;

use vars qw/ $VERSION $REVISION /;
$REVISION = '$Id: Token.pm,v 1.5 2005/10/08 19:45:55 ovid Exp $';
$VERSION  = '3.0';

sub new {
    my ($class, $token) = @_;
    $class->_croak("This class should not be instantiated") if __PACKAGE__ eq $class;
    return bless $token, $class;
}

sub _croak {
    my ($proto, $message) = @_;
    require Carp;
    Carp::croak($message);
}

sub _carp {
    my ($proto, $message) = @_;
    require Carp;
    Carp::carp($message);
}

sub is_tag         {}
sub is_start_tag   {}
sub is_end_tag     {}
sub is_text        {}
sub is_comment     {}
sub is_declaration {}
sub is_pi          {}
sub is_process_instruction {}

sub rewrite_tag    { shift }
sub delete_attr    {}
sub set_attr       {}
sub get_tag        {}
sub return_tag     {}  # deprecated
sub get_attr       {}
sub return_attr    {}  # deprecated
sub get_attrseq    {}
sub return_attrseq {}  # deprecated
sub get_token0     {}
sub return_token0  {}  # deprecated

# get_foo methods

sub return_text {
    my ($self) = @_;
    $self->_carp('return_text() is deprecated.  Use as_is() instead');
    goto &as_is;
}

sub as_is { return shift->[-1] }

1;

__END__