1package Pod::Simple::PullParserStartToken;
2use strict;
3use warnings;
4use Pod::Simple::PullParserToken ();
5our @ISA = ('Pod::Simple::PullParserToken');
6our $VERSION = '3.45';
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 SEE ALSO
115
116L<Pod::Simple::PullParserToken>, L<Pod::Simple>, L<Pod::Simple::Subclassing>
117
118=head1 SUPPORT
119
120Questions or discussion about POD and Pod::Simple should be sent to the
121pod-people@perl.org mail list. Send an empty email to
122pod-people-subscribe@perl.org to subscribe.
123
124This module is managed in an open GitHub repository,
125L<https://github.com/perl-pod/pod-simple/>. Feel free to fork and contribute, or
126to clone L<https://github.com/perl-pod/pod-simple.git> and send patches!
127
128Patches against Pod::Simple are welcome. Please send bug reports to
129<bug-pod-simple@rt.cpan.org>.
130
131=head1 COPYRIGHT AND DISCLAIMERS
132
133Copyright (c) 2002 Sean M. Burke.
134
135This library is free software; you can redistribute it and/or modify it
136under the same terms as Perl itself.
137
138This program is distributed in the hope that it will be useful, but
139without any warranty; without even the implied warranty of
140merchantability or fitness for a particular purpose.
141
142=head1 AUTHOR
143
144Pod::Simple was created by Sean M. Burke <sburke@cpan.org>.
145But don't bother him, he's retired.
146
147Pod::Simple is maintained by:
148
149=over
150
151=item * Allison Randal C<allison@perl.org>
152
153=item * Hans Dieter Pearcey C<hdp@cpan.org>
154
155=item * David E. Wheeler C<dwheeler@cpan.org>
156
157=back
158
159=cut
160