3 package Pod::Simple::PullParserStartToken;
4 use Pod::Simple::PullParserToken ();
5 @ISA = ('Pod::Simple::PullParserToken');
8 sub new { # Class->new(tagname, optional_attrhash);
10 return bless ['start', @_], ref($class) || $class;
15 sub tagname { (@_ == 2) ? ($_[0][1] = $_[1]) : $_[0][1] }
16 sub tag { shift->tagname(@_) }
18 sub is_tagname { $_[0][1] eq $_[1] }
19 sub is_tag { shift->is_tagname(@_) }
22 sub attr_hash { $_[0][2] ||= {} }
25 if(@_ == 2) { # Reading: $token->attr('attrname')
26 ${$_[0][2] || return undef}{ $_[1] };
27 } elsif(@_ > 2) { # Writing: $token->attr('attrname', 'newval')
28 ${$_[0][2] ||= {}}{ $_[1] } = $_[2];
32 'usage: $object->attr("val") or $object->attr("key", "newval")');
44 Pod::Simple::PullParserStartToken -- start-tokens from Pod::Simple::PullParser
48 (See L<Pod::Simple::PullParser>)
52 When you do $parser->get_token on a L<Pod::Simple::PullParser> object, you might
53 get an object of this class.
55 This is a subclass of L<Pod::Simple::PullParserToken> and inherits all its methods,
56 and adds these methods:
62 This returns the tagname for this start-token object.
63 For example, parsing a "=head1 ..." line will give you
64 a start-token with the tagname of "head1", token(s) for its
65 content, and then an end-token with the tagname of "head1".
67 =item $token->tagname(I<somestring>)
69 This changes the tagname for this start-token object.
70 You probably won't need
73 =item $token->tag(...)
75 A shortcut for $token->tagname(...)
77 =item $token->is_tag(I<somestring>) or $token->is_tagname(I<somestring>)
79 These are shortcuts for C<< $token->tag() eq I<somestring> >>
81 =item $token->attr(I<attrname>)
83 This returns the value of the I<attrname> attribute for this start-token
86 For example, parsing a LZ<><Foo/"Bar"> link will produce a start-token
87 with a "to" attribute with the value "Foo", a "type" attribute with the
88 value "pod", and a "section" attribute with the value "Bar".
90 =item $token->attr(I<attrname>, I<newvalue>)
92 This sets the I<attrname> attribute for this start-token object to
93 I<newvalue>. You probably won't need to do this.
95 =item $token->attr_hash
97 This returns the hashref that is the attribute set for this start-token.
98 This is useful if (for example) you want to ask what all the attributes
99 are -- you can just do C<< keys %{$token->attr_hash} >>
104 You're unlikely to ever need to construct an object of this class for
105 yourself, but if you want to, call
107 Pod::Simple::PullParserStartToken->new( I<tagname>, I<attrhash> )
112 L<Pod::Simple::PullParserToken>, L<Pod::Simple>, L<Pod::Simple::Subclassing>
114 =head1 COPYRIGHT AND DISCLAIMERS
116 Copyright (c) 2002 Sean M. Burke. All rights reserved.
118 This library is free software; you can redistribute it and/or modify it
119 under the same terms as Perl itself.
121 This program is distributed in the hope that it will be useful, but
122 without any warranty; without even the implied warranty of
123 merchantability or fitness for a particular purpose.
127 Sean M. Burke C<sburke@cpan.org>