This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Underscore the non-official version number
[perl5.git] / lib / Pod / Simple / PullParserStartToken.pm
CommitLineData
351625bd
SP
1
2require 5;
3package Pod::Simple::PullParserStartToken;
4use Pod::Simple::PullParserToken ();
5@ISA = ('Pod::Simple::PullParserToken');
6use strict;
7
8sub new { # Class->new(tagname, optional_attrhash);
9 my $class = shift;
10 return bless ['start', @_], ref($class) || $class;
11}
12
13# Purely accessors:
14
15sub tagname { (@_ == 2) ? ($_[0][1] = $_[1]) : $_[0][1] }
16sub tag { shift->tagname(@_) }
17
18sub is_tagname { $_[0][1] eq $_[1] }
19sub is_tag { shift->is_tagname(@_) }
20
21
22sub attr_hash { $_[0][2] ||= {} }
23
24sub attr {
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];
29 } else {
30 require Carp;
31 Carp::croak(
32 'usage: $object->attr("val") or $object->attr("key", "newval")');
33 return undef;
34 }
35}
36
371;
38
39
40__END__
41
42=head1 NAME
43
44Pod::Simple::PullParserStartToken -- start-tokens from Pod::Simple::PullParser
45
46=head1 SYNOPSIS
47
48(See L<Pod::Simple::PullParser>)
49
50=head1 DESCRIPTION
51
52When you do $parser->get_token on a L<Pod::Simple::PullParser> object, you might
53get an object of this class.
54
55This is a subclass of L<Pod::Simple::PullParserToken> and inherits all its methods,
56and adds these methods:
57
58=over
59
60=item $token->tagname
61
62This returns the tagname for this start-token object.
63For example, parsing a "=head1 ..." line will give you
64a start-token with the tagname of "head1", token(s) for its
65content, and then an end-token with the tagname of "head1".
66
67=item $token->tagname(I<somestring>)
68
69This changes the tagname for this start-token object.
70You probably won't need
71to do this.
72
73=item $token->tag(...)
74
75A shortcut for $token->tagname(...)
76
77=item $token->is_tag(I<somestring>) or $token->is_tagname(I<somestring>)
78
79These are shortcuts for C<< $token->tag() eq I<somestring> >>
80
81=item $token->attr(I<attrname>)
82
83This returns the value of the I<attrname> attribute for this start-token
84object, or undef.
85
86For example, parsing a LZ<><Foo/"Bar"> link will produce a start-token
87with a "to" attribute with the value "Foo", a "type" attribute with the
88value "pod", and a "section" attribute with the value "Bar".
89
90=item $token->attr(I<attrname>, I<newvalue>)
91
92This sets the I<attrname> attribute for this start-token object to
93I<newvalue>. You probably won't need to do this.
94
95=item $token->attr_hash
96
97This returns the hashref that is the attribute set for this start-token.
98This is useful if (for example) you want to ask what all the attributes
99are -- you can just do C<< keys %{$token->attr_hash} >>
100
101=back
102
103
104You're unlikely to ever need to construct an object of this class for
105yourself, but if you want to, call
106C<<
107Pod::Simple::PullParserStartToken->new( I<tagname>, I<attrhash> )
108>>
109
110=head1 SEE ALSO
111
112L<Pod::Simple::PullParserToken>, L<Pod::Simple>, L<Pod::Simple::Subclassing>
113
114=head1 COPYRIGHT AND DISCLAIMERS
115
116Copyright (c) 2002 Sean M. Burke. All rights reserved.
117
118This library is free software; you can redistribute it and/or modify it
119under the same terms as Perl itself.
120
121This program is distributed in the hope that it will be useful, but
122without any warranty; without even the implied warranty of
123merchantability or fitness for a particular purpose.
124
125=head1 AUTHOR
126
127Sean M. Burke C<sburke@cpan.org>
128
129=cut
130