3 package Pod::Simple::LinkSection;
4 # Based somewhat dimly on Array::Autojoin
7 use Pod::Simple::BlackBox;
9 use overload( # So it'll stringify nice
10 '""' => \&Pod::Simple::BlackBox::stringify_lol,
11 'bool' => \&Pod::Simple::BlackBox::stringify_lol,
12 # '.=' => \&tack_on, # grudgingly support
14 'fallback' => 1, # turn on cleverness
18 $_[0] = ['', {}, "$_[0]" ];
19 return $_[0][2] .= $_[1];
23 goto &Pod::Simple::BlackBox::stringify_lol;
26 goto &Pod::Simple::BlackBox::stringify_lol;
31 $class = ref($class) || $class;
34 if (!ref($_[0] || '')) { # most common case: one bare string
35 return bless ['', {}, $_[0] ], $class;
36 } elsif( ref($_[0] || '') eq 'ARRAY') {
37 $new = [ @{ $_[0] } ];
39 Carp::croak( "$class new() doesn't know to clone $new" );
42 $new = [ '', {}, @_ ];
45 # By now it's a treelet: [ 'foo', {}, ... ]
46 foreach my $x (@$new) {
47 if(ref($x || '') eq 'ARRAY') {
48 $x = $class->new($x); # recurse
49 } elsif(ref($x || '') eq 'HASH') {
55 return bless $new, $class;
58 # Not much in this class is likely to be link-section specific --
59 # but it just so happens that link-sections are about the only treelets
60 # that are exposed to the user.
66 # TODO: let it be an option whether a given subclass even wants little treelets?
73 Pod::Simple::LinkSection -- represent "section" attributes of L codes
81 This class is not of interest to general users.
83 Pod::Simple uses this class for representing the value of the
84 "section" attribute of "L" start-element events. Most applications
85 can just use the normal stringification of objects of this class;
86 they stringify to just the text content of the section,
88 C<< LZ<><Stuff/foo> >>, and "bar" for
89 C<< LZ<><Stuff/bIZ<><ar>> >>.
91 However, anyone particularly interested in getting the full value of
92 the treelet, can just traverse the content of the treeleet
93 @$treelet_object. To wit:
96 % perl -MData::Dumper -e
97 "use base qw(Pod::Simple::Methody);
98 sub start_L { print Dumper($_[1]{'section'} ) }
99 __PACKAGE__->new->parse_string_document('=head1 L<Foo/bI<ar>baz>>')
110 ], 'Pod::Simple::LinkSection' ),
112 ], 'Pod::Simple::LinkSection' );
114 But stringify it and you get just the text content:
116 % perl -MData::Dumper -e
117 "use base qw(Pod::Simple::Methody);
118 sub start_L { print Dumper( '' . $_[1]{'section'} ) }
119 __PACKAGE__->new->parse_string_document('=head1 L<Foo/bI<ar>baz>>')
129 =head1 COPYRIGHT AND DISCLAIMERS
131 Copyright (c) 2002 Sean M. Burke. All rights reserved.
133 This library is free software; you can redistribute it and/or modify it
134 under the same terms as Perl itself.
136 This program is distributed in the hope that it will be useful, but
137 without any warranty; without even the implied warranty of
138 merchantability or fitness for a particular purpose.
142 Sean M. Burke C<sburke@cpan.org>