Merge branch 'vincent/rvalue_stmt_given' into blead
[p5sagit/p5-mst-13.2.git] / cpan / Pod-Simple / lib / Pod / Simple / PullParserStartToken.pm
CommitLineData
351625bd 1
2require 5;
3package Pod::Simple::PullParserStartToken;
4use Pod::Simple::PullParserToken ();
351625bd 5use strict;
a242eeb4 6use vars qw(@ISA $VERSION);
7@ISA = ('Pod::Simple::PullParserToken');
316e9929 8$VERSION = '3.14';
351625bd 9
10sub new { # Class->new(tagname, optional_attrhash);
11 my $class = shift;
12 return bless ['start', @_], ref($class) || $class;
13}
14
15# Purely accessors:
16
17sub tagname { (@_ == 2) ? ($_[0][1] = $_[1]) : $_[0][1] }
18sub tag { shift->tagname(@_) }
19
20sub is_tagname { $_[0][1] eq $_[1] }
21sub is_tag { shift->is_tagname(@_) }
22
23
24sub attr_hash { $_[0][2] ||= {} }
25
26sub attr {
27 if(@_ == 2) { # Reading: $token->attr('attrname')
28 ${$_[0][2] || return undef}{ $_[1] };
29 } elsif(@_ > 2) { # Writing: $token->attr('attrname', 'newval')
30 ${$_[0][2] ||= {}}{ $_[1] } = $_[2];
31 } else {
32 require Carp;
33 Carp::croak(
34 'usage: $object->attr("val") or $object->attr("key", "newval")');
35 return undef;
36 }
37}
38
391;
40
41
42__END__
43
44=head1 NAME
45
46Pod::Simple::PullParserStartToken -- start-tokens from Pod::Simple::PullParser
47
48=head1 SYNOPSIS
49
50(See L<Pod::Simple::PullParser>)
51
52=head1 DESCRIPTION
53
54When you do $parser->get_token on a L<Pod::Simple::PullParser> object, you might
55get an object of this class.
56
57This is a subclass of L<Pod::Simple::PullParserToken> and inherits all its methods,
58and adds these methods:
59
60=over
61
62=item $token->tagname
63
64This returns the tagname for this start-token object.
65For example, parsing a "=head1 ..." line will give you
66a start-token with the tagname of "head1", token(s) for its
67content, and then an end-token with the tagname of "head1".
68
69=item $token->tagname(I<somestring>)
70
71This changes the tagname for this start-token object.
72You probably won't need
73to do this.
74
75=item $token->tag(...)
76
77A shortcut for $token->tagname(...)
78
79=item $token->is_tag(I<somestring>) or $token->is_tagname(I<somestring>)
80
81These are shortcuts for C<< $token->tag() eq I<somestring> >>
82
83=item $token->attr(I<attrname>)
84
85This returns the value of the I<attrname> attribute for this start-token
86object, or undef.
87
88For example, parsing a LZ<><Foo/"Bar"> link will produce a start-token
89with a "to" attribute with the value "Foo", a "type" attribute with the
90value "pod", and a "section" attribute with the value "Bar".
91
92=item $token->attr(I<attrname>, I<newvalue>)
93
94This sets the I<attrname> attribute for this start-token object to
95I<newvalue>. You probably won't need to do this.
96
97=item $token->attr_hash
98
99This returns the hashref that is the attribute set for this start-token.
100This is useful if (for example) you want to ask what all the attributes
101are -- you can just do C<< keys %{$token->attr_hash} >>
102
103=back
104
105
106You're unlikely to ever need to construct an object of this class for
107yourself, but if you want to, call
108C<<
109Pod::Simple::PullParserStartToken->new( I<tagname>, I<attrhash> )
110>>
111
112=head1 SEE ALSO
113
114L<Pod::Simple::PullParserToken>, L<Pod::Simple>, L<Pod::Simple::Subclassing>
115
a242eeb4 116=head1 SEE ALSO
117
118L<Pod::Simple::PullParserToken>, L<Pod::Simple>, L<Pod::Simple::Subclassing>
119
120=head1 SUPPORT
121
122Questions or discussion about POD and Pod::Simple should be sent to the
123pod-people@perl.org mail list. Send an empty email to
124pod-people-subscribe@perl.org to subscribe.
125
126This module is managed in an open GitHub repository,
127L<http://github.com/theory/pod-simple/>. Feel free to fork and contribute, or
128to clone L<git://github.com/theory/pod-simple.git> and send patches!
129
130Patches against Pod::Simple are welcome. Please send bug reports to
131<bug-pod-simple@rt.cpan.org>.
132
351625bd 133=head1 COPYRIGHT AND DISCLAIMERS
134
433cf6b4 135Copyright (c) 2002 Sean M. Burke.
351625bd 136
137This library is free software; you can redistribute it and/or modify it
138under the same terms as Perl itself.
139
140This program is distributed in the hope that it will be useful, but
141without any warranty; without even the implied warranty of
142merchantability or fitness for a particular purpose.
143
144=head1 AUTHOR
145
a242eeb4 146Pod::Simple was created by Sean M. Burke <sburke@cpan.org>.
147But don't bother him, he's retired.
351625bd 148
a242eeb4 149Pod::Simple is maintained by:
150
151=over
152
153=item * Allison Randal C<allison@perl.org>
154
155=item * Hans Dieter Pearcey C<hdp@cpan.org>
351625bd 156
a242eeb4 157=item * David E. Wheeler C<dwheeler@cpan.org>
158
159=back
160
161=cut