blib/lib/OODoc/Text.pm untested

filter: Statementstmt 0.0% 0 / 61 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 19 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 18 Podpod 0.0% 0 / 12 totaltotal 0.0% 0 / 118 SCAR 34.0
CC
5
Cov
0%
findDescriptionObject
12.0
container
6.0
manual
6.0
CRAP 30.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;
9 use vars '$VERSION';
10 $VERSION = '2.02';
11  
12 use base 'OODoc::Object';
13  
14 use strict;
15 use warnings;
16  
17 use Log::Report 'oodoc';
18  
19  
20 use overload '==' => sub {$_[0]->unique == $_[1]->unique}
21 , '!=' => sub {$_[0]->unique != $_[1]->unique}
22 , '""' => sub {$_[0]->name}
23 , 'cmp' => sub {$_[0]->name cmp "$_[1]"}
24 , 'bool' => sub {1};
25  
26 #-------------------------------------------
27  
28  
29 my $unique = 1;
30  
31 sub init($)
32 { my ($self, $args) = @_;
33 $self->SUPER::init($args) or return;
34  
35 $self->{OT_name} = delete $args->{name};
36  
37 my $nr = $self->{OT_linenr} = delete $args->{linenr} or panic;
38 $self->{OT_type} = delete $args->{type} or panic;
39  
40 exists $args->{container} # may be explicit undef
41 or panic "no text container specified for the {pkg} object"
42 , pkg => ref $self;
43  
44 # may be undef
45 $self->{OT_container}= delete $args->{container};
46  
47 $self->{OT_descr} = delete $args->{description} || '';
48 $self->{OT_examples} = [];
49 $self->{OT_unique} = $unique++;
50  
51 $self;
52 }
53  
54 #-------------------------------------------
55  
56  
57 sub name() {shift->{OT_name}}
58  
59  
60 sub type() {shift->{OT_type}}
61  
62  
63 sub description()
64 { my $text = shift->{OT_descr};
65 my @lines = split /^/m, $text;
66 shift @lines while @lines && $lines[ 0] =~ m/^\s*$/;
67 pop @lines while @lines && $lines[-1] =~ m/^\s*$/;
68 join '', @lines;
69 }
70  
71  
72 sub container(;$)
73 { my $self = shift;
74 @_ ? ($self->{OT_container} = shift) : $self->{OT_container};
75 }
76  
77  
78 sub manual(;$)
79 { my $self = shift;
80 @_ ? $self->SUPER::manual(@_)
81 : $self->container->manual;
82 }
83  
84  
85 sub unique() {shift->{OT_unique}}
86  
87  
88 sub where()
89 { my $self = shift;
90 ($self->manual->source, $self->{OT_linenr});
91 }
92  
93 #-------------------------------------------
94  
95  
96 sub openDescription() { \shift->{OT_descr} }
97  
98  
99 sub findDescriptionObject()
100 { my $self = shift;
101 return $self if length $self->description;
102  
103 my @descr = map { $_->findDescriptionObject } $self->extends;
104 wantarray ? @descr : $descr[0];
105 }
106  
107  
108 sub example($)
109 { my ($self, $example) = @_;
110 push @{$self->{OT_examples}}, $example;
111 $example;
112 }
113  
114  
115 sub examples() { @{shift->{OT_examples}} }
116  
117 #-------------------------------------------
118  
119  
120 1;