blib/lib/OODoc/Text/Section.pm untested

filter: Statementstmt 0.0% 0 / 62 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 12 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 15 Podpod 0.0% 0 / 9 totaltotal 0.0% 0 / 110 SCAR 40.3
CC
7
Cov
0%
findSubroutine
12.0
findEntry
12.0
subsection
6.0
CRAP 56.0
1 # Copyrights 2003-2021 by [Mark Overmeer].
2 # For other contributors see ChangeLog.
3 # See the manual pages for details on the licensing terms.
4 # Pod stripped from pm file by OODoc 2.02.
5 # This code is part of perl distribution OODoc. It is licensed under the
6 # same terms as Perl itself: https://spdx.org/licenses/Artistic-2.0.html
7  
8 package OODoc::Text::Section;
9 use vars '$VERSION';
10 $VERSION = '2.02';
11  
12 use base 'OODoc::Text::Structure';
13  
14 use strict;
15 use warnings;
16  
17 use Log::Report 'oodoc';
18 use List::Util 'first';
19  
20  
21 sub init($)
22 { my ($self, $args) = @_;
23 $args->{type} ||= 'Section';
24 $args->{level} ||= 2;
25 $args->{container} ||= delete $args->{chapter} or panic;
26  
27 $self->SUPER::init($args) or return;
28  
29 $self->{OTS_subsections} = [];
30 $self;
31 }
32  
33 sub emptyExtension($)
34 { my ($self, $container) = @_;
35 my $empty = $self->SUPER::emptyExtension($container);
36 my @subsections = map $_->emptyExtension($empty), $self->subsections;
37 $empty->subsections(@subsections);
38 $empty;
39 }
40  
41 #-------------------------------------------
42  
43  
44 sub chapter() { shift->container }
45  
46 sub path()
47 { my $self = shift;
48 $self->chapter->path . '/' . $self->name;
49 }
50  
51 sub findSubroutine($)
52 { my ($self, $name) = @_;
53 my $sub = $self->SUPER::findSubroutine($name);
54 return $sub if defined $sub;
55  
56 foreach my $subsection ($self->subsections)
57 { my $sub = $subsection->findSubroutine($name);
58 return $sub if defined $sub;
59 }
60  
61 undef;
62 }
63  
64 sub findEntry($)
65 { my ($self, $name) = @_;
66 return $self if $self->name eq $name;
67 my $subsect = $self->subsection($name);
68 defined $subsect ? $subsect : ();
69 }
70  
71 sub all($@)
72 { my $self = shift;
73 ($self->SUPER::all(@_), map {$_->all(@_)} $self->subsections);
74 }
75  
76 #-------------------------------------------
77  
78  
79 sub subsection($)
80 { my ($self, $thing) = @_;
81 if(ref $thing)
82 { push @{$self->{OTS_subsections}}, $thing;
83 return $thing;
84 }
85  
86 first {$_->name eq $thing} $self->subsections;
87 }
88  
89  
90 sub subsections(;@)
91 { my $self = shift;
92 if(@_)
93 { $self->{OTS_subsections} = [ @_ ];
94 $_->container($self) for @_;
95 }
96  
97 @{$self->{OTS_subsections}};
98 }
99  
100  
101 1;