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

filter: Statementstmt 0.0% 0 / 100 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 15 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 18 Podpod 0.0% 0 / 13 totaltotal 0.0% 0 / 168 CC 12 SCAR 31.3
CC
12
Cov
0%
location
72.0
collectedOptions
12.0
extends
6.0
CRAP 22.9
1 # Copyrights 2003-2015 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.01.
5  
6 package OODoc::Text::Subroutine;
7 use vars '$VERSION';
8 $VERSION = '2.01';
9  
10 use base 'OODoc::Text';
11  
12 use strict;
13 use warnings;
14  
15 use Log::Report 'oodoc';
16  
17  
18 sub init($)
19 { my ($self, $args) = @_;
20  
21 exists $args->{name}
22 or error __x"no name for subroutine";
23  
24 $self->SUPER::init($args)
25 or return;
26  
27 $self->{OTS_param} = delete $args->{parameters};
28 $self->{OTS_options} = {};
29 $self->{OTS_defaults} = {};
30 $self->{OTS_diags} = [];
31 $self;
32 }
33  
34 #-------------------------------------------
35  
36  
37 sub extends($)
38 { my $self = shift;
39 @_ or return $self->SUPER::extends;
40  
41 my $super = shift;
42 if($self->type ne $super->type)
43 { my ($fn1, $ln1) = $self->where;
44 my ($fn2, $ln2) = $super->where;
45 my ($t1, $t2 ) = ($self->type, $super->type);
46  
47 warning __x"subroutine {name}() extended by different type:\n {type1} in {file1} line {line1}\n {type2} in {file2} line {line2}"
48 , name => "$self"
49 , type1 => $t1, file1 => $fn1, line1 => $ln1
50 , type2 => $t2, file2 => $fn2, line2 => $ln2;
51 }
52  
53 $self->SUPER::extends($super);
54 }
55  
56 #-------------------------------------------
57  
58  
59 sub parameters() {shift->{OTS_param}}
60  
61 #-------------------------------------------
62  
63  
64 sub location($)
65 { my ($self, $manual) = @_;
66 my $container = $self->container;
67 my $super = $self->extends
68 or return $container;
69  
70 my $superloc = $super->location;
71 my $superpath = $superloc->path;
72 my $mypath = $container->path;
73  
74 return $container if $superpath eq $mypath;
75
76 if(length $superpath < length $mypath)
77 { return $container
78 if substr($mypath, 0, length($superpath)+1) eq "$superpath/";
79 }
80 elsif(substr($superpath, 0, length($mypath)+1) eq "$mypath/")
81 { if($superloc->isa("OODoc::Text::Chapter"))
82 { return $self->manual
83 ->chapter($superloc->name);
84 }
85 elsif($superloc->isa("OODoc::Text::Section"))
86 { return $self->manual
87 ->chapter($superloc->chapter->name)
88 ->section($superloc->name);
89 }
90 else
91 { return $self->manual
92 ->chapter($superloc->chapter->name)
93 ->section($superloc->section->name)
94 ->subsection($superloc->name);
95 }
96 }
97  
98 unless($manual->inherited($self))
99 { my ($myfn, $myln) = $self->where;
100 my ($superfn, $superln) = $super->where;
101  
102 warning __x"subroutine {name}() location conflict:\n {path1} in {file1} line {line1}\n {path2} in {file2} line {line2}"
103 , name => "$self"
104 , path1 => $mypath, file1 => $myfn, line1 => $myln
105 , path2 => $superpath, file2 => $superfn, line2 => $superln;
106 }
107  
108 $container;
109 }
110  
111  
112 sub path() { shift->container->path }
113  
114 #-------------------------------------------
115  
116  
117 sub default($)
118 { my ($self, $it) = @_;
119 ref $it
120 or return $self->{OTS_defaults}{$it};
121  
122 my $name = $it->name;
123 $self->{OTS_defaults}{$name} = $it;
124 $it;
125 }
126  
127 #-------------------------------------------
128  
129  
130 sub defaults() { values %{shift->{OTS_defaults}} }
131  
132  
133 sub option($)
134 { my ($self, $it) = @_;
135 ref $it
136 or return $self->{OTS_options}{$it};
137  
138 my $name = $it->name;
139 $self->{OTS_options}{$name} = $it;
140 $it;
141 }
142  
143  
144  
145 sub findOption($)
146 { my ($self, $name) = @_;
147 my $option = $self->option($name);
148 return $option if $option;
149  
150 my $extends = $self->extends or return;
151 $extends->findOption($name);
152 }
153  
154  
155 sub options() { values %{shift->{OTS_options}} }
156  
157  
158 sub diagnostic($)
159 { my ($self, $diag) = @_;
160 push @{$self->{OTS_diags}}, $diag;
161 $diag;
162 }
163  
164  
165 sub diagnostics() { @{shift->{OTS_diags}} }
166  
167  
168 sub collectedOptions(@)
169 { my ($self, %args) = @_;
170 my @extends = $self->extends;
171 my %options;
172 foreach ($self->extends)
173 { my $options = $_->collectedOptions;
174 @options{ keys %$options } = values %$options;
175 }
176  
177 $options{$_->name}[0] = $_ for $self->options;
178  
179 foreach my $default ($self->defaults)
180 { my $name = $default->name;
181  
182 unless(exists $options{$name})
183 { my ($fn, $ln) = $default->where;
184 warning __x"no option {name} for default in {file} line {line}"
185 , name => $name, file => $fn, line => $ln;
186 next;
187 }
188 $options{$name}[1] = $default;
189 }
190  
191 foreach my $option ($self->options)
192 { my $name = $option->name;
193 next if defined $options{$name}[1];
194  
195 my ($fn, $ln) = $option->where;
196 warning __x"no default for option {name} defined in {file} line {line}"
197 , name => $name, file => $fn, line => $ln;
198  
199 my $default = $options{$name}[1] =
200 OODoc::Text::Default->new
201 ( name => $name, value => 'undef'
202 , subroutine => $self, linenr => $ln
203 );
204  
205 $self->default($default);
206 }
207  
208 \%options;
209 }
210  
211 1;