File Coverage

lib/OODoc/Text/Section.pm
Criterion Covered Total %
statement 15 56 26.7
branch 0 16 0.0
condition 0 7 0.0
subroutine 5 15 33.3
pod 7 9 77.7
total 27 103 26.2


line stmt bran cond sub pod time code
1             # This code is part of Perl distribution OODoc version 3.05.
2             # The POD got stripped from this file by OODoc version 3.05.
3             # For contributors see file ChangeLog.
4              
5             # This software is copyright (c) 2003-2025 by Mark Overmeer.
6              
7             # This is free software; you can redistribute it and/or modify it under
8             # the same terms as the Perl 5 programming language system itself.
9             # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
10              
11              
12             package OODoc::Text::Section;{
13             our $VERSION = '3.05';
14             }
15              
16 1     1   1647 use parent 'OODoc::Text::Structure';
  1         2  
  1         10  
17              
18 1     1   107 use strict;
  1         3  
  1         42  
19 1     1   5 use warnings;
  1         3  
  1         65  
20              
21 1     1   4 use Log::Report 'oodoc';
  1         2  
  1         17  
22 1     1   391 use List::Util 'first';
  1         2  
  1         867  
23              
24             #--------------------
25              
26             sub init($)
27 0     0 0   { my ($self, $args) = @_;
28 0   0       $args->{type} ||= 'Section';
29 0   0       $args->{level} ||= 2;
30 0 0 0       $args->{container} ||= delete $args->{chapter} or panic;
31              
32 0 0         $self->SUPER::init($args) or return;
33              
34 0           $self->{OTS_subsections} = [];
35 0           $self;
36             }
37              
38             sub emptyExtension($)
39 0     0 1   { my ($self, $container) = @_;
40 0           my $empty = $self->SUPER::emptyExtension($container);
41 0           my @subsections = map $_->emptyExtension($empty), $self->subsections;
42 0           $empty->subsections(@subsections);
43 0           $empty;
44             }
45              
46             #--------------------
47              
48 0     0 1   sub chapter() { $_[0]->container }
49              
50             sub path()
51 0     0 1   { my $self = shift;
52 0           $self->chapter->path . '/' . $self->name;
53             }
54              
55             sub findSubroutine($)
56 0     0 0   { my ($self, $name) = @_;
57 0           my $sub = $self->SUPER::findSubroutine($name);
58 0 0         return $sub if defined $sub;
59              
60 0           foreach my $subsection ($self->subsections)
61 0           { my $sub = $subsection->findSubroutine($name);
62 0 0         return $sub if defined $sub;
63             }
64              
65 0           undef;
66             }
67              
68             sub findEntry($)
69 0     0 1   { my ($self, $name) = @_;
70 0 0         return $self if $self->name eq $name;
71 0           my $subsect = $self->subsection($name);
72 0 0         defined $subsect ? $subsect : ();
73             }
74              
75             sub all($@)
76 0     0 1   { my $self = shift;
77 0           ( $self->SUPER::all(@_), map $_->all(@_), $self->subsections );
78             }
79              
80             #--------------------
81              
82             sub subsection($)
83 0     0 1   { my ($self, $thing) = @_;
84 0 0         if(ref $thing)
85 0           { push @{$self->{OTS_subsections}}, $thing;
  0            
86 0           return $thing;
87             }
88              
89 0     0     first {$_->name eq $thing} $self->subsections;
  0            
90             }
91              
92              
93             sub subsections(;@)
94 0     0 1   { my $self = shift;
95 0 0         if(@_)
96 0           { $self->{OTS_subsections} = [ @_ ];
97 0           $_->container($self) for @_;
98             }
99              
100 0           @{$self->{OTS_subsections}};
  0            
101             }
102              
103             *nest = \*subsections;
104              
105             1;