blib/lib/Liveman/Cpanfile.pm

filter: Statementstmt 92.2% 95 / 103 Branchbran 69.5% 32 / 46 Conditioncond 65.2% 15 / 23 MC/DCmcdc 53.8% 7 / 13 Subroutinesub 90.0% 18 / 20 Podpod 90.9% 10 / 11 totaltotal 81.9% 177 / 216 CC 40 SCAR 17.8
CC
40
Cov
83%
get_pkg_version
20.0
deps
8.0
t_deps
8.0
CRAP 5.9
« blib/lib/Liveman/CoverBadge.pm ↑ Summary /usr/local/bin/prove »
1 package Liveman::Cpanfile;
2  
3 4 ▶use common::sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 4 ▶use File::Find::Wanted qw/find_wanted/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use File::Slurper qw/read_text write_text/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # Конструктор
9 1 ▶sub new {
Subroutine new: called CC=2 SCAR=8.1
Pod documented
10 1 my $cls = shift;
11 1 ▶ bless {@_}, ref $cls || $cls
Condition33%1/3
ref $cls || $cls
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $cls || $cls
ref $cls $cls
Truth table33%1/3
A || B
A= ref $clsB= $cls
ABresult
1X1
011
000
12 }
13  
14 # Пакет из пути
15 4 ▶sub pkg_from_path(;$) {
Subroutine pkg_from_path: called CC=3 SCAR=11.0
Pod documented
16 4 ▶ my ($pkg) = @_? @_: $_;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 2 2 4
17 4 my @pkg = File::Spec->splitdir($pkg);
18 4 ▶ shift @pkg if $pkg[0] eq "lib"; # Удаляем lib/
Branch: 1 branch
BranchTrueFalseTotal
if $pkg[0] eq "lib" 4 0 4
19 4 $pkg[$#pkg] =~ s!\.\w+$!!; # Удаляем расширение
20 4 join "::", @pkg
21 }
22  
23 # Список файлов scripts/* и bin/*
24 2 ▶sub sc {
Subroutine sc: called CC=2 SCAR=6.9
Pod documented
25 2 my ($self) = @_;
26 2 ▶ @{$self->{sc} //= [sort(find_wanted(sub { -f $_ and do { open my $f, '<:encoding(UTF-8)', $_; my $x = <$f> =~ /^#!.*\bperl\b/; close $f; $x } }, "script", "bin"))]}
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
-f $_ and do { open my $f, "<:encoding(UTF-8)", $_; my $x = readline($f) =~ /^#!.*\bperl\b/u; close $f; $x } 2 2 4
Condition100%2/2
$self->{"sc"} //= [sort(find_wanted(sub { -f $_ and do { open my $f, "<:encoding(UTF-8)", $_; my $x = readline($f) =~ /^#!.*\bperl\b/u; close $f; $x }; } , "script", "bin"))]
l!l
11
MC/DC100%1/1
$self->{"sc"} //= [sort(find_wanted(sub { -f $_ and do { open my $f, "<:encoding(UTF-8)", $_; my $x = readline($f) =~ /^#!.*\bperl\b/u; close $f; $x }; } , "script", "bin"))]
$self->{"sc"}
Truth table100%2/2
A
A= $self->{"sc"}
Aresult
11
00
27 }
28  
29 # Список файлов lib/*.pm
30 3 ▶sub pm {
Subroutine pm: called CC=2 SCAR=6.9
Pod documented
31 3 my ($self) = @_;
32 3 ▶ @{$self->{pm} //= [sort(find_wanted(sub { /\.pm$/ and -f $_ }, "lib"))]}
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
/\.pm$/u and -f $_ 2 3 5
Condition100%2/2
$self->{"pm"} //= [sort(find_wanted(sub { /\.pm$/u and -f $_; } , "lib"))]
l!l
21
MC/DC100%1/1
$self->{"pm"} //= [sort(find_wanted(sub { /\.pm$/u and -f $_; } , "lib"))]
$self->{"pm"}
Truth table100%2/2
A
A= $self->{"pm"}
Aresult
11
00
33 }
34  
35 # Список пакетов проекта
36 3 ▶sub mod {
Subroutine mod: called CC=2 SCAR=6.9
Pod documented
37 3 my ($self) = @_;
38 3 ▶ @{$self->{mod} //= [map pkg_from_path, $self->pm]}
Condition100%2/2
$self->{"mod"} //= [map(&pkg_from_path(), $self->pm)]
l!l
21
MC/DC100%1/1
$self->{"mod"} //= [map(&pkg_from_path(), $self->pm)]
$self->{"mod"}
Truth table100%2/2
A
A= $self->{"mod"}
Aresult
11
00
39 }
40  
41 # Список *.md файлов
42 3 ▶sub md {
Subroutine md: called CC=2 SCAR=6.9
Pod documented
43 3 my ($self) = @_;
44 3 ▶ @{$self->{md} //= [sort(find_wanted(sub { /\.md$/ and -f $_ }, "lib"))]}
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
/\.md$/u and -f $_ 1 4 5
Condition100%2/2
$self->{"md"} //= [sort(find_wanted(sub { /\.md$/u and -f $_; } , "lib"))]
l!l
21
MC/DC100%1/1
$self->{"md"} //= [sort(find_wanted(sub { /\.md$/u and -f $_; } , "lib"))]
$self->{"md"}
Truth table100%2/2
A
A= $self->{"md"}
Aresult
11
00
45 }
46  
47 # Список внедрённых в *.md пакетов
48 2 ▶sub md_mod {
Subroutine md_mod: called CC=7 SCAR=19.5
Pod documented
49 2 my ($self) = @_;
50 2 ▶ @{$self->{md_mod} //= [do {
Condition100%2/2
$self->{"md_mod"} //= [do { my %mod; foreach my $md ($self->md) { open my $f, "<", $md or die "Can't open ${md}: $!"; while (defined($_ = readline $f)) { if (/^```perl\s*$/u ... /^```$/u) { ++$mod{$1} while /\bpackage\s+([a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*)/gu; } ; } ; close $f; } ; sort keys %mod }]
l!l
11
MC/DC100%1/1
$self->{"md_mod"} //= [do { my %mod; foreach my $md ($self->md) { open my $f, "<", $md or die "Can't open ${md}: $!"; while (defined($_ = readline $f)) { if (/^```perl\s*$/u ... /^```$/u) { ++$mod{$1} while /\bpackage\s+([a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*)/gu; } ; } ; close $f; } ; sort keys %mod }]
$self->{"md_mod"}
Truth table100%2/2
A
A= $self->{"md_mod"}
Aresult
11
00
51 1 my %mod;
52 1 for my $md ($self->md) {
53 1 ▶ open my $f, '<', $md or die "Can't open $md: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $f, "<", $md or die "Can't open ${md}: $!" 1 0 1
54 1 ▶ while(<$f>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $f)) 11 1 12
55 11 ▶ if(/^```perl\s*$/ ... /^```$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^```perl\s*$/u ... /^```$/u) 8 3 11
56 8 ▶ $mod{$1}++ while /\bpackage\s+([a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*)/g;
Branch: 1 branch
BranchTrueFalseTotal
/\bpackage\s+([a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*)/gu and do { ++$mod{$1} } 2 8 10
57 }
58 }
59 1 close $f;
60 }
61 1 sort keys %mod
62 }]}
63 }
64  
65 # Список пакетов, используемых в скриптах и модулях
66 4 my $qr_mod = qr/
67 '(?<p> [\w:]+ )'
68 | "(?<p> [\w:]+ )"
69 | (?:q|qq|qw) [^\w\s] \s* (?<p> [\w:]+ (?: \s+ [\w:]+ )* ) \s* [^\w\s]
70 /ax;
71 18 ▶sub _used_mod {
Subroutine _used_mod: called CC=5 SCAR=18.4
72 18 my ($s) = @_;
73 18 my @mod;
74
75 18 ▶ push @mod, pkg_from_path $1 while $s =~ /(?:^|[{};])[ \t]*require\s*['"]([\w\/\.]+)['"]/gma;
Branch: 1 branch
BranchTrueFalseTotal
$s =~ m[(?:^|[{};])[ \t]*require\s*['"]([\w/\.]+)['"]]agm and do { push @mod, &pkg_from_path($1) } 0 18 18
76
77 18 ▶ push @mod, $1 while $s =~ /(?:^|[{};])[ \t]*(?:use|require)\s+([a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*)/gma;
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /(?:^|[{};])[ \t]*(?:use|require)\s+([a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*)/agm and do { push @mod, $1 } 23 18 41
78  
79 0 ▶ push @mod, map { /$qr_mod/ && split /\s+/, $+{p} } split /\s*,\s*/, $1 while $s =~ /(?:^|[{};]) [\ \t]* (?:with|extends) \s* ((?:
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /(?:^|[{};]) [\ \t]* (?:with|extends) \s* ((?: (?: $qr_mod ) (?:\s*,\s*)* )+) \s* ; /agmx and do { push @mod, map({/$qr_mod/u and split(/\s+/u, $+{"p"}, 0);} split(/\s*,\s*/u, $1, 0)) } 0 18 18
Condition0%0/3
/$qr_mod/u && split(/\s+/u, $+{'p'}, 0)
!ll&&!rl&&r
000
MC/DC0%0/2
/$qr_mod/u && split(/\s+/u, $+{'p'}, 0)
/$qr_mod/u split(/\s+/u, $+{'p'}, 0)
Truth table0%0/3
A && B
A= /$qr_mod/uB= split(/\s+/u, $+{'p'}, 0)
ABresult
0X0
100
111
80 (?: $qr_mod ) (?:\s*,\s*)*
81 )+) \s* ;
82 /agmx;
83
84 @mod
85 18 }
86  
87 # Список зависимостей явно указанных в скриптах и модулях (- mod)
88 3 ▶sub deps {
Subroutine deps: called CC=8 SCAR=20.8
Pod documented
89 3 my ($self) = @_;
90 3 ▶ @{$self->{deps} //= [do {
Condition100%2/2
$self->{"deps"} //= [do { my %mod; foreach my $pl ($self->pm, $self->sc) { open my $f, "<", $pl or die "Can't open ${pl}: $!"; while (defined($_ = readline $f)) { next if /^\s*#/u; last if /^(__END__|__DATA__)\s*$/u; ++$mod{$_} foreach (_used_mod($_)); } ; close $f; } ; delete @mod{$self->mod}; sort {fc $a cmp fc $b;} keys %mod }]
l!l
21
MC/DC100%1/1
$self->{"deps"} //= [do { my %mod; foreach my $pl ($self->pm, $self->sc) { open my $f, "<", $pl or die "Can't open ${pl}: $!"; while (defined($_ = readline $f)) { next if /^\s*#/u; last if /^(__END__|__DATA__)\s*$/u; ++$mod{$_} foreach (_used_mod($_)); } ; close $f; } ; delete @mod{$self->mod}; sort {fc $a cmp fc $b;} keys %mod }]
$self->{"deps"}
Truth table100%2/2
A
A= $self->{"deps"}
Aresult
11
00
91 1 my %mod;
92
93 1 for my $pl ($self->pm, $self->sc) {
94 4 ▶ open my $f, '<', $pl or die "Can't open $pl: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $f, "<", $pl or die "Can't open ${pl}: $!" 4 0 4
95 4 ▶ while(<$f>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $f)) 11 4 15
96 11 ▶ next if /^\s*#/;
Branch: 1 branch
BranchTrueFalseTotal
if /^\s*#/u 2 9 11
97 9 ▶ last if /^(__END__|__DATA__)\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^(__END__|__DATA__)\s*$/u 0 9 9
98
99 9 $mod{$_}++ for _used_mod($_);
100 }
101 4 close $f;
102 }
103  
104 1 delete @mod{$self->mod};
105 1 sort { fc $a cmp fc $b } keys %mod
106 }]}
107 }
108  
109 # Список зависимостей из тестов (- mod - deps - md_mod)
110 2 ▶sub t_deps {
Subroutine t_deps: called CC=8 SCAR=20.8
Pod documented
111 2 my ($self) = @_;
112 2 ▶ @{$self->{t_deps} //= [do {
Condition100%2/2
$self->{"t_deps"} //= [do { my %mod; require Liveman; ++$mod{$_} foreach (_used_mod($Liveman::TEST_HEAD)); foreach my $md ($self->md) { open my $f, "<", $md or die "Can't open ${md}: $!"; while (defined($_ = readline $f)) { if (/^```perl\s*$/u ... /^```$/u) { ++$mod{$_} foreach (_used_mod($_)); } ; } ; close $f; } ; delete @mod{$self->mod}; delete @mod{$self->md_mod}; delete @mod{$self->deps}; sort {fc $a cmp fc $b;} keys %mod }]
l!l
11
MC/DC100%1/1
$self->{"t_deps"} //= [do { my %mod; require Liveman; ++$mod{$_} foreach (_used_mod($Liveman::TEST_HEAD)); foreach my $md ($self->md) { open my $f, "<", $md or die "Can't open ${md}: $!"; while (defined($_ = readline $f)) { if (/^```perl\s*$/u ... /^```$/u) { ++$mod{$_} foreach (_used_mod($_)); } ; } ; close $f; } ; delete @mod{$self->mod}; delete @mod{$self->md_mod}; delete @mod{$self->deps}; sort {fc $a cmp fc $b;} keys %mod }]
$self->{"t_deps"}
Truth table100%2/2
A
A= $self->{"t_deps"}
Aresult
11
00
113 1 my %mod;
114  
115 1 require Liveman;
116 1 $mod{$_}++ for _used_mod($Liveman::TEST_HEAD);
117
118 1 for my $md ($self->md) {
119 1 ▶ open my $f, '<', $md or die "Can't open $md: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $f, "<", $md or die "Can't open ${md}: $!" 1 0 1
120 1 ▶ while(<$f>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $f)) 11 1 12
121 11 ▶ if(/^```perl\s*$/ ... /^```$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^```perl\s*$/u ... /^```$/u) 8 3 11
122 8 $mod{$_}++ for _used_mod($_);
123 }
124 }
125 1 close $f;
126 }
127  
128 1 delete @mod{$self->mod};
129 1 delete @mod{$self->md_mod};
130 1 delete @mod{$self->deps};
131 1 sort { fc $a cmp fc $b } keys %mod
132 }]}
133 }
134  
135 4 my %PKG_VERSION;
136 # Возвращает пакет с версией в иерархии
137 0 ▶sub get_pkg_version {
Subroutine get_pkg_version: not called CC=4 SCAR=30.0
Pod undocumented
138 0 my ($self, $pkg) = @_;
139
140 0 for(;;) {
141 0 ▶ my $version = $PKG_VERSION{$pkg} //= `perl -e 'use $pkg; print $pkg->VERSION' 2> /dev/null`;
Condition0%0/3
$PKG_VERSION{$pkg} //= `perl -e 'use $pkg; print $pkg->VERSION' 2> /dev/null`
l!l&&r!l&&!r
000
MC/DC0%0/2
$PKG_VERSION{$pkg} //= `perl -e 'use $pkg; print $pkg->VERSION' 2> /dev/null`
$PKG_VERSION{$pkg} `perl -e 'use $pkg; print $pkg->VERSION' 2> /dev/null`
Truth table0%0/3
A //= B
A= $PKG_VERSION{$pkg}B= `perl -e 'use $pkg; print $pkg->VERSION' 2> /dev/null`
ABresult
1X1
011
000
142 0 ▶ return $pkg, $version if $version ne '';
Branch: 1 branch
BranchTrueFalseTotal
if $version ne "" 0 0 0
143 0 ▶ $pkg =~ s/::\w+$// or return;
Branch: 1 branch
BranchTrueFalseTotal
$pkg =~ s/::\w+$//u or return 0 0 0
144 }
145 }
146  
147 # Возвращает примерный cpanfile
148 1 ▶sub cpanfile {
Subroutine cpanfile: called CC=2 SCAR=7.6
Pod documented
149 1 my ($self, $with_version) = @_;
150  
151 my $req = $with_version
152 0 ▶ ? sub { my ($pkg, $version) = $self->get_pkg_version($_); $pkg? "requires '$pkg', '$version';": () }
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$pkg ? : 0 0 0
153 1 ▶ : sub { "requires '$_';" };
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
$with_version ? : 0 1 1
154
155 1 my $requires = join "\n", List::Util::uniqstr map { $req->() } $self->deps;
156 1 my $t_requires = join "", List::Util::uniqstr map { "\t${ \$req->() }\n" } $self->t_deps;
157  
158 1 << "END";
159 requires 'perl', '5.22.0';
160  
161 on 'develop' => sub {
162 requires 'App::cpm';
163 requires 'CPAN::Uploader';
164 requires 'Data::Printer', '1.000004';
165 requires 'Minilla', 'v3.1.19';
166 requires 'Liveman', '1.0';
167 requires 'Software::License::GPL_3';
168 requires 'Test::CPAN::Meta';
169 requires 'Test::MinimumVersion::Fast';
170 requires 'Test::PAUSE::Permissions';
171 requires 'Test::Pod';
172 requires 'Test::Spellunker';
173 requires 'V';
174 requires 'Version::Next';
175 };
176  
177 on 'test' => sub {\n$t_requires};
178  
179 $requires
180 END
181 }
182  
183 4 1;
184  
185 __END__
« blib/lib/Liveman/CoverBadge.pm ↑ Summary /usr/local/bin/prove »