blib/lib/Module/Manifest/Skip.pm

filter: Statementstmt 64.5% 40 / 62 Branchbran 25.0% 6 / 24 Conditioncond 23.5% 4 / 17 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 81.8% 9 / 11 Podpod 0.0% 0 / 6 totaltotal 45.7% 59 / 129 CC 19 SCAR 26.9
CC
19
Cov
49%
skip_template
39.0
add
12.0
import
9.8
CRAP 14.8
↑ Summary
1 5 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Module::Manifest::Skip;
3 5 our $VERSION = '0.24';
4  
5 5 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 5 has text => (
8 is => 'ro',
9 builder => 'text__',
10 lazy => 1,
11 );
12  
13 has old_text => (
14 is => 'ro',
15 1 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
16 1 my $self = shift;
17 1 return $self->read_file('MANIFEST.SKIP', 1);
18 },
19 5 );
20  
21 6 ▶sub import {
Subroutine import: called CC=4 SCAR=22.9
22 6 my ($package, $command) = @_;
23 6 ▶ if ($command and $command eq 'create') {
Branch: 1 branch
BranchTrueFalseTotal
if ($command and $command eq "create") 0 6 6
Condition33%1/3
$command and $command eq "create"
!ll&&!rl&&r
600
MC/DC0%0/2
$command and $command eq "create"
$command $command eq "create"
Truth table33%1/3
A and B
A= $commandB= $command eq "create"
ABresult
0X0
100
111
24 0 my $text = $package->new->text;
25 0 ▶ open MS, '>', 'MANIFEST.SKIP'
Branch: 1 branch
BranchTrueFalseTotal
open MS, ">", "MANIFEST.SKIP" or die "Can't open MANIFEST.SKIP for output:\n$!" 0 0 0
26 or die "Can't open MANIFEST.SKIP for output:\n$!";
27 0 print MS $text;
28 0 close MS;
29 0 exit;
30 }
31 }
32  
33 0 ▶sub add {
Subroutine add: not called CC=3 SCAR=24.8
Pod undocumented
34 0 my $self = shift;
35 0 ▶ my $addition = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $addition = shift() or return 0 0 0
36 0 chomp $addition;
37 0 ▶ if (not $self->{add_occurred}++) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"add_occurred"}++) 0 0 0
38 0 $self->{text} =~ s/\n+\z/\n\n/;
39 }
40 0 $self->{text} .= $addition . "\n";
41 }
42  
43 0 ▶sub remove {
Subroutine remove: not called CC=2 SCAR=17.9
Pod undocumented
44 0 my $self = shift;
45 0 ▶ my $exclude = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $exclude = shift() or return 0 0 0
46 0 $self->{text} =~ s/^(\Q$exclude\E)$/# $1/mg;
47 }
48  
49 1 ▶sub text__ {
Subroutine text__: called CC=2 SCAR=7.0
Pod undocumented
50 1 my $self = shift;
51 1 my $old = $self->old_text;
52 1 ▶ my $text = ($old =~ /\A(\S.*?\n\n)/s) ? $1 : '';
Branch: 1 branch
BranchTrueFalseTotal
$old =~ /\A(\S.*?\n\n)/s ? : 0 1 1
53 1 chomp $text;
54 1 $text .= $self->skip_template;
55 1 local $self->{text} = $text;
56 1 $self->reduce;
57 1 return $self->{text};
58 }
59  
60 1 ▶sub reduce {
Subroutine reduce: called CC=2 SCAR=7.6
Pod undocumented
61 1 my $self = shift;
62 1 ▶ while ($self->{text} =~ s/^- (.*)$/* $1/m) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"text"} =~ s/^- (.*)$/* $1/m) 0 1 1
63 0 $self->remove($1);
64 }
65 1 $self->{text} =~ s/^\* /- /mg;
66 }
67  
68 1 ▶sub skip_template {
Subroutine skip_template: called CC=8 SCAR=36.6
Pod undocumented
69 1 my $self = shift;
70 1 ▶ my $path = $INC{'Module/Manifest/Skip.pm'} or die;
Branch: 1 branch
BranchTrueFalseTotal
my $path = $INC{"Module/Manifest/Skip.pm"} or die 1 0 1
71 1 ▶ if (-e 'lib/Module/Manifest/Skip.pm') {
Branch: 2 branches
BranchTrueFalseTotal
if (-e 'lib/Module/Manifest/Skip.pm') { } 1 0 1
elsif ($path =~ s[(\S.*?)[\\/]?\blib\b.*][$1] and -e "$path/share") { } 0 0 0
72 1 return $self->read_file('share/MANIFEST.SKIP');
73 }
74 ▶ elsif ($path =~ s!(\S.*?)[\\/]?\blib\b.*!$1! and -e "$path/share") {
Condition0%0/3
$path =~ s[(\S.*?)[\\/]?\blib\b.*][$1] and -e "$path/share"
!ll&&!rl&&r
000
MC/DC0%0/2
$path =~ s[(\S.*?)[\\/]?\blib\b.*][$1] and -e "$path/share"
$path =~ s[(\S.*?)[\\/]?\blib\b.*][$1] -e "$path/share"
Truth table0%0/3
A and B
A= $path =~ s[(\S.*?)[\\/]?\blib\b.*][$1]B= -e "$path/share"
ABresult
0X0
100
111
75 0 return $self->read_file("$path/share/MANIFEST.SKIP");
76 }
77 else {
78 0 require File::ShareDir;
79 0 require File::Spec;
80 0 my $dir = File::ShareDir::dist_dir('Module-Manifest-Skip');
81 0 my $file = File::Spec->catfile($dir, 'MANIFEST.SKIP');
82 0 ▶ die "Can't find MANIFEST.SKIP share file for Module::Manifest::Skip"
Branch: 1 branch
BranchTrueFalseTotal
unless $dir and -f $file and -r $file 0 0 0
Condition0%0/6
$dir and -f $file and -r $file
!ll&&!rl&&r
000
$dir and -f $file
!ll&&!rl&&r
000
MC/DC0%0/3
$dir and -f $file and -r $file
$dir -f $file -r $file
Truth table0%0/4
A and B and C
A= $dirB= -f $fileC= -r $file
ABCresult
0XX0
10X0
1100
1111
83 unless $dir and -f $file and -r $file;
84 0 return $self->read_file($file);
85 }
86 }
87  
88 10 ▶sub read_file {
Subroutine read_file: called CC=4 SCAR=14.2
Pod undocumented
89 10 my ($self, $file, $ignore) = @_;
90 10 ▶ open FILE, $file or
Branch: 1 branch
BranchTrueFalseTotal
open FILE, $file or $ignore and return "" or die "Can't open '${file}' for input:\n$!" 9 0 9
Condition60%3/5
open FILE, $file or $ignore and return ""
l!l&&r!l&&!r
910
$ignore and return ""
!ll
01
MC/DC0%0/2
open FILE, $file or $ignore and return ""
open FILE, $file $ignore
Truth table66%2/3
A or B
A= open FILE, $fileB= $ignore
ABresult
1X1
011
000
91 $ignore and return '' or
92 die "Can't open '$file' for input:\n$!";
93 9 my $text = do { local $/; <FILE> };
94 9 close FILE;
95 9 $text =~ s/\r//g;
96 9 return $text;
97 }
98  
99 5 1;
↑ Summary