lib/OODoc/Manifest.pm

filter: Statementstmt 38.6% 29 / 75 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 45.0% 9 / 20 Podpod 87.5% 7 / 8 totaltotal 34.3% 45 / 131 SCAR 47.9
CC
17
Cov
29%
write
30.0
init
20.0
read
20.0
CRAP 120.4
« blib/lib/OODoc/Text/Subroutine.pm ↑ Summary lib/OODoc/Text/Chapter.pm »
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::Manifest;
9 2 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 $VERSION = '2.02';
11  
12 2 ▶use base 'OODoc::Object';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 2 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶use File::Basename 'dirname';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use Log::Report 'oodoc';
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21  
22 2 ▶use overload '@{}' => sub { [ shift->files ] };
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine __ANON__: not called CC=1 SCAR=0.2
23 2 ▶use overload bool => sub {1};
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine __ANON__: not called CC=1 SCAR=0.2
24  
25 #-------------------------------------------
26  
27  
28 sub init($)
29 0 ▶{ my ($self, $args) = @_;
Subroutine init: not called CC=4 SCAR=30.0
Pod undocumented
30 0 ▶ $self->SUPER::init($args) or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init($args) or return 0 0 0
31  
32 0 my $filename = $self->{OM_filename} = delete $args->{filename};
33  
34 0 $self->{O_files} = {};
35 0 ▶ $self->read if defined $filename && -e $filename;
Branch: 1 branch
BranchTrueFalseTotal
if defined $filename and -e $filename 0 0 0
Condition0%0/3
defined $filename and -e $filename
!ll&&!rl&&r
000
MC/DC0%0/2
defined $filename and -e $filename
defined $filename -e $filename
Truth table0%0/3
A and B
A= defined $filenameB= -e $filename
ABresult
0X0
100
111
36 0 $self->modified(0);
37 0 $self;
38 }
39  
40 #-------------------------------------------
41  
42  
43 0 ▶sub filename() {shift->{OM_filename}}
Subroutine filename: not called CC=1 SCAR=6.9
Pod documented
44  
45 #-------------------------------------------
46  
47  
48 0 ▶sub files() { keys %{shift->{O_files}} }
Subroutine files: not called CC=1 SCAR=6.9
Pod documented
49  
50 #-------------------------------------------
51  
52  
53 sub add($)
54 0 ▶{ my $self = shift;
Subroutine add: not called CC=3 SCAR=24.8
Pod documented
55 0 ▶ while(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
56 0 { my $add = $self->relative(shift);
57 0 ▶ $self->modified(1) unless exists $self->{O_file}{$add};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"O_file"}{$add} 0 0 0
58 0 $self->{O_files}{$add}++;
59 }
60 0 $self;
61 }
62  
63 #-------------------------------------------
64  
65  
66 sub read()
67 0 ▶{ my $self = shift;
Subroutine read: not called CC=4 SCAR=30.0
Pod documented
68 0 my $filename = $self->filename;
69 0 ▶ my $file = IO::File->new($filename, "r")
Branch: 1 branch
BranchTrueFalseTotal
my $file = "IO::File"->new($filename, "r") or &fault(&__x("cannot read manifest file {file}", "file", $filename)) 0 0 0
70 or fault __x"cannot read manifest file {file}", file => $filename;
71  
72 0 my @dist = $file->getlines;
73 0 $file->close;
74  
75 0 s/\s+.*\n?$// for @dist;
76 0 $self->{O_files}{$_}++ foreach @dist;
77 0 $self;
78 }
79  
80 #-------------------------------------------
81  
82  
83 sub modified(;$)
84 0 ▶{ my $self = shift;
Subroutine modified: not called CC=2 SCAR=17.9
Pod documented
85 0 ▶ @_ ? $self->{OM_modified} = @_ : $self->{OM_modified};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
86 }
87  
88 #-------------------------------------------
89  
90  
91 sub write()
92 0 ▶{ my $self = shift;
Subroutine write: not called CC=5 SCAR=34.0
Pod documented
93 0 ▶ return unless $self->modified;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->modified 0 0 0
94 0 ▶ my $filename = $self->filename || return $self;
Condition0%0/2
$self->filename || (return $self)
l!l
00
MC/DC0%0/1
$self->filename || (return $self)
$self->filename
Truth table0%0/2
A
A= $self->filename
Aresult
11
00
95  
96 0 ▶ my $file = IO::File->new($filename, "w")
Branch: 1 branch
BranchTrueFalseTotal
my $file = "IO::File"->new($filename, "w") or &fault(&__x("cannot write manifest {file}", "file", $filename)) 0 0 0
97 or fault __x"cannot write manifest {file}", file => $filename;
98  
99 0 $file->print($_, "\n") foreach sort $self->files;
100 0 $file->close;
101  
102 0 $self->modified(0);
103 0 $self;
104 }
105  
106 0 ▶sub DESTROY() { shift->write }
Subroutine DESTROY: not called CC=1 SCAR=6.9
107  
108 #-------------------------------------------
109  
110  
111 sub relative($)
112 0 ▶{ my ($self, $filename) = @_;
Subroutine relative: not called CC=4 SCAR=30.0
Pod documented
113  
114 0 my $dir = dirname $self->filename;
115 0 ▶ return $filename if $dir eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if $dir eq "." 0 0 0
116  
117 # normalize path for windows
118 0 s!\\!/!g for $filename, $dir;
119  
120 0 ▶ if(substr($filename, 0, length($dir)+1) eq "$dir/")
Branch: 1 branch
BranchTrueFalseTotal
if (substr($filename, 0, length($dir) + 1) eq "$dir/") 0 0 0
121 0 { substr $filename, 0, length($dir)+1, '';
122 0 return $filename;
123 }
124  
125 0 warn "WARNING: MANIFEST file ".$self->filename
126 . " lists filename outside (sub)directory: $filename\n";
127  
128 0 $filename;
129 }
130  
131 #-------------------------------------------
132  
133  
134 2 1;
« blib/lib/OODoc/Text/Subroutine.pm ↑ Summary lib/OODoc/Text/Chapter.pm »