lib/OODoc/Manifest.pm

filter: Statementstmt 34.2% 24 / 70 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 38.8% 7 / 18 Podpod 87.5% 7 / 8 totaltotal 30.6% 38 / 124 CC 17 SCAR 25.9
CC
17
Cov
25%
write
30.0
init
20.0
read
20.0
CRAP 13.3
« lib/OODoc/Parser.pm ↑ Summary lib/OODoc/Text/Option.pm »
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::Manifest;{
13 2 our $VERSION = '3.05';
14 }
15  
16 2 ▶use parent 'OODoc::Object';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 2 ▶use Log::Report 'oodoc';
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 2 ▶use File::Basename 'dirname';
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 #--------------------
26  
27 0 ▶use overload '@{}' => sub { [ shift->files ] };
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine __ANON__: not called CC=1 SCAR=0.2
28 0 ▶use overload bool => sub {1};
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine __ANON__: not called CC=1 SCAR=0.2
29  
30 #--------------------
31  
32 sub init($)
33 0 ▶{ my ($self, $args) = @_;
Subroutine init: not called CC=4 SCAR=30.0
Pod undocumented
34 0 ▶ $self->SUPER::init($args) or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init($args) or return 0 0 0
35  
36 0 my $filename = $self->{OM_filename} = delete $args->{filename};
37  
38 0 $self->{OM_files} = {};
39 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
40 0 $self->modified(0);
41 0 $self;
42 }
43  
44 #--------------------
45  
46 0 ▶sub filename() { $_[0]->{OM_filename} }
Subroutine filename: not called CC=1 SCAR=6.9
Pod documented
47  
48 #--------------------
49  
50 0 ▶sub files() { keys %{ $_[0]->{OM_files}} }
Subroutine files: not called CC=1 SCAR=6.9
Pod documented
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->{OM_files}{$add}++;
59 }
60 0 $self;
61 }
62  
63 #--------------------
64  
65 sub read()
66 0 ▶{ my $self = shift;
Subroutine read: not called CC=4 SCAR=30.0
Pod documented
67 0 my $filename = $self->filename;
68  
69 0 ▶ open my $file, "<:encoding(utf8)", $filename
Branch: 1 branch
BranchTrueFalseTotal
open my $file, "<:encoding(utf8)", $filename 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->{OM_files}{$_}++ foreach @dist;
77 0 $self;
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 sub write()
88 0 ▶{ my $self = shift;
Subroutine write: not called CC=5 SCAR=34.0
Pod documented
89 0 ▶ return unless $self->modified;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->modified 0 0 0
90 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
91  
92 0 ▶ open my $file, ">:encoding(utf8)", $filename
Branch: 1 branch
BranchTrueFalseTotal
open my $file, ">:encoding(utf8)", $filename or &fault(&__x("cannot write manifest {file}", "file", $filename)) 0 0 0
93 or fault __x"cannot write manifest {file}", file => $filename;
94  
95 0 $file->print($_, "\n") foreach sort $self->files;
96 0 $file->close;
97  
98 0 $self->modified(0);
99 0 $self;
100 }
101  
102 0 ▶sub DESTROY() { $_[0]->write }
Subroutine DESTROY: not called CC=1 SCAR=6.9
103  
104  
105 sub relative($)
106 0 ▶{ my ($self, $filename) = @_;
Subroutine relative: not called CC=4 SCAR=30.0
Pod documented
107  
108 0 my $dir = dirname $self->filename;
109 0 ▶ return $filename if $dir eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if $dir eq "." 0 0 0
110  
111 # normalize path for windows
112 0 s!\\!/!g for $filename, $dir;
113  
114 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
115 0 { substr $filename, 0, length($dir)+1, '';
116 0 return $filename;
117 }
118  
119 0 warning __x"MANIFEST file {file} lists filename outside (sub)directory: {out}", file => $self->filename, out => $filename;
120  
121 0 $filename;
122 }
123  
124 2 1;
« lib/OODoc/Parser.pm ↑ Summary lib/OODoc/Text/Option.pm »