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