File Coverage

blib/lib/Pod/Simple/LinkSection.pm
Criterion Covered Total %
statement 26 31 83.8
branch 8 10 80.0
condition 7 11 63.6
subroutine 6 8 75.0
pod 0 4 0.0
total 47 64 73.4


line stmt bran cond sub pod time code
1             package Pod::Simple::LinkSection;
2             # Based somewhat dimly on Array::Autojoin
3              
4 70     70   77126 use strict;
  70         116  
  70         2160  
5 70     70   243 use warnings;
  70         85  
  70         2570  
6 70     70   45756 use Pod::Simple::BlackBox;
  70         247  
  70         4686  
7             our $VERSION = '3.48';
8              
9             use overload( # So it'll stringify nice
10 70         458 '""' => \&Pod::Simple::BlackBox::stringify_lol,
11             'bool' => \&Pod::Simple::BlackBox::stringify_lol,
12             # '.=' => \&tack_on, # grudgingly support
13              
14             'fallback' => 1, # turn on cleverness
15 70     70   33793 );
  70         79256  
16              
17             sub tack_on {
18 0     0 0 0 $_[0] = ['', {}, "$_[0]" ];
19 0         0 return $_[0][2] .= $_[1];
20             }
21              
22             sub as_string {
23 0     0 0 0 goto &Pod::Simple::BlackBox::stringify_lol;
24             }
25             sub stringify {
26 2     2 0 1376 goto &Pod::Simple::BlackBox::stringify_lol;
27             }
28              
29             sub new {
30 538     538 0 127083 my $class = shift;
31 538   33     1070 $class = ref($class) || $class;
32 538         591 my $new;
33 538 50       782 if(@_ == 1) {
34 538 100 50     1364 if (!ref($_[0] || '')) { # most common case: one bare string
    50 50        
35 166         611 return bless ['', {}, $_[0] ], $class;
36             } elsif( ref($_[0] || '') eq 'ARRAY') {
37 372         371 $new = [ @{ $_[0] } ];
  372         748  
38             } else {
39 0         0 Carp::croak( "$class new() doesn't know to clone $new" );
40             }
41             } else { # misc stuff
42 0         0 $new = [ '', {}, @_ ];
43             }
44              
45             # By now it's a treelet: [ 'foo', {}, ... ]
46 372         517 foreach my $x (@$new) {
47 1321 100 100     2979 if(ref($x || '') eq 'ARRAY') {
    100 100        
48 127         260 $x = $class->new($x); # recurse
49             } elsif(ref($x || '') eq 'HASH') {
50 372         608 $x = { %$x };
51             }
52             # otherwise leave it.
53             }
54              
55 372         737 return bless $new, $class;
56             }
57              
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.
61              
62             1;
63              
64             __END__