lib/Project/Easy/Helper/Status.pm

filter: Statementstmt 84.8% 129 / 152 Branchbran 55.5% 40 / 72 Conditioncond 33.3% 4 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 76.9% 10 / 13 Podpod 0.0% 0 / 8 totaltotal 69.0% 183 / 265 CC 49 SCAR 24.9
CC
49
Cov
73%
status_ok
19.3
status_ok
19.3
__ANON__
5.1
CRAP 12.0
« lib/Project/Easy/DB.pm ↑ Summary lib/Project/Easy.pm »
1 package Project::Easy::Helper;
2  
3 7 ▶use Class::Easy;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 ▶sub run_script {
Subroutine run_script: called CC=3 SCAR=12.7
Pod undocumented
6 4 ▶ my $script = shift;
Subroutine run_script: called CC=3 SCAR=12.7
Pod undocumented
7 4 my $path = shift;
8
9 4 my $out = `$script 2>&1`;
10
11 6 my $res = $? >> 8;
12 6 ▶ if ($res == 0) {
Branch: 4 branches
BranchTrueFalseTotal
if ($res == 0) { } 6 0 6
elsif ($res == 255) { } 0 0 0
if ($res == 0) { } 3 0 3
elsif ($res == 255) { } 0 0 0
13 6 debug $path, " … OK\n";
14 } elsif ($res == 255) {
15 0 warn $out, $path, " … DIED\n";
16 0 exit;
17 } else {
18 0 warn $out, $path, " … FAILED $res TESTS\n";
19 0 exit;
20 }
21 }
22  
23 # TODO: when status run, new available scripts must be created
24 1 ▶sub status {
Subroutine status: called CC=2 SCAR=8.0
Pod undocumented
25 0 ▶ my ($project_class, $libs);
Subroutine status: called CC=2 SCAR=8.0
Pod undocumented
26
27 0 eval {
28 0 ($project_class, $libs) = &_script_wrapper;
29 };
30
31 1 ▶ if ($@) {
Branch: 2 branches
BranchTrueFalseTotal
if ($@) 0 1 1
if ($@) 0 1 1
32 0 &status_fail ($project_class, $libs);
33 0 die $@;
34 }
35
36 1 return &status_ok ($project_class, $libs);
37
38 }
39  
40 0 ▶sub status_fail {
Subroutine status_fail: not called CC=1 SCAR=6.9
Pod undocumented
41 0 ▶ my ($project_class, $libs, $params) = @_;
Subroutine status_fail: called CC=1 SCAR=6.9
Pod undocumented
42
43 # my $root = $project_class->root;
44
45 # here we must recreate var directories
46 # TODO: make it by Project::Easy::Helper service 'install' routine
47
48 # my $global_config = $project_class->conf_path->deserialize;
49 }
50  
51 1 ▶sub status_ok {
Subroutine status_ok: called CC=16 SCAR=29.6
Pod undocumented
52 0 ▶ my ($pack, $libs, $params) = @_;
Subroutine status_ok: not called CC=16 SCAR=29.6
Pod undocumented
53
54 1 my $root = $pack->root;
55
56 0 my $data_files = file->__data__files;
57
58 1 create_scripts ($root, $data_files);
59
60 1 my $lib_dir = $root->append ('lib')->as_dir;
61
62 1 my $includes = join ' ', map {"-I$_"} (@$libs, @INC);
63
64 1 my $files = [];
65 1 my $all_uses = {};
66 11 my $all_packs = {};
67
68 8 ▶ $lib_dir->scan_tree (sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
69 1 ▶ my $file = shift;
Subroutine __ANON__: called CC=5 SCAR=16.1
70
71 1 ▶ return 1 if $file->type eq 'dir';
Branch: 2 branches
BranchTrueFalseTotal
if $file->type eq "dir" 5 5 10
if $file->type eq "dir" 5 3 8
72
73 1 ▶ if ($file =~ /\.pm$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($file =~ /\.pm$/) 5 0 5
if ($file =~ /\.pm$/) 3 0 3
74 10 push @$files, $file;
75 10 my $content = $file->contents;
76  
77 5 ▶ while ($content =~ m/^(use|package) ([^\$\;\s]+)/igms){
Branch: 2 branches
BranchTrueFalseTotal
if ($content =~ /^(use|package) ([^\$\;\s]+)/gims) 15 5 20
if ($content =~ /^(use|package) ([^\$\;\s]+)/gims) 9 3 12
78 5 ▶ if ($1 eq 'use') {
Branch: 2 branches
BranchTrueFalseTotal
if ($1 eq 'use') { } 10 5 15
if ($1 eq 'use') { } 6 3 9
79 5 $all_uses->{$2} = $file;
80 } else {
81 5 $all_packs->{$2} = $file;
82 }
83 }
84 }
85 1 });
86
87 1 foreach (keys %$all_uses) {
88 1 ▶ delete $all_uses->{$_}
Branch: 2 branches
BranchTrueFalseTotal
if /^[a-z][a-z0-9]+$/ 1 1 2
if /^[a-z][a-z0-9]+$/ 1 1 2
89 if /^[a-z][a-z0-9]+$/;
90 }
91
92 1 my $failed = {};
93 1 my $external = {};
94
95 # here we try to find dependencies
96 2 foreach (keys %$all_uses) {
97 $external->{$_} = $all_uses->{$_}
98 1 ▶ unless exists $all_packs->{$_};
Branch: 2 branches
BranchTrueFalseTotal
unless exists $all_packs->{$_} 1 0 1
unless exists $all_packs->{$_} 1 0 1
99
100 $failed->{$_} = $all_uses->{$_}
101 1 ▶ if ! try_to_use ($_) and ! exists $all_packs->{$_};
Branch: 2 branches
BranchTrueFalseTotal
unless try_to_use($_) or exists $all_packs->{$_} 0 1 1
unless try_to_use($_) or exists $all_packs->{$_} 0 1 1
Condition33%2/6
try_to_use($_) or exists $all_packs->{$_}
l!l&&r!l&&!r
100
try_to_use($_) or exists $all_packs->{$_}
l!l&&r!l&&!r
100
MC/DC0%0/2
try_to_use($_) or exists $all_packs->{$_}
try_to_use($_) exists $all_packs->{$_}
MC/DC0%0/2
try_to_use($_) or exists $all_packs->{$_}
try_to_use($_) exists $all_packs->{$_}
Truth table33%1/3
A or B
A= try_to_use($_)B= exists $all_packs->{$_}
ABresult
1X1
011
000
Truth table33%1/3
A or B
A= try_to_use($_)B= exists $all_packs->{$_}
ABresult
1X1
011
000
102 }
103
104 1 debug "external modules: ", join (' ', sort keys %$external), "\n";
105
106 1 ▶ warn "requirements not satisfied. you must install these modules:\ncpan -i ",
Branch: 2 branches
BranchTrueFalseTotal
if scalar keys %$failed 0 1 1
if scalar keys %$failed 0 1 1
107 join (' ', sort keys %$failed), "\n"
108 if scalar keys %$failed;
109
110 1 foreach my $file (@$files) {
111 1 my $abs_path = $file->abs_path;
112 1 my $rel_path = $file->rel_path ((ref $root)->current->abs_path);
113 1 my $project_path = $file->rel_path ($root->abs_path);
114  
115 # warn "$^X -c $rel_path";
116
117 5 run_script ("$^X $includes -c $abs_path", $rel_path);
118
119 }
120  
121 # TODO: move db check code to unit
122
123 5 my $db_outdated = 0;
124
125 5 foreach my $datasource (keys %{$pack->config->{db}}) {
126 1 my $ver;
127 1 eval {$ver = update_schema (datasource => $datasource, dry_run => 1);};
128
129 next
130 2 ▶ unless defined $ver; # if update file not defined
Branch: 2 branches
BranchTrueFalseTotal
unless defined $ver 0 2 2
unless defined $ver 0 1 1
131
132 2 ▶ die "datasource '$datasource' error: $@"
Branch: 2 branches
BranchTrueFalseTotal
if $@ 0 2 2
if $@ 0 1 1
133 if $@;
134
135 2 ▶ if (!$@ and ($ver->{db} ne $ver->{schema})) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $@ and $ver->{"db"} ne $ver->{"schema"}) 0 2 2
if (not $@ and $ver->{"db"} ne $ver->{"schema"}) 0 1 1
Condition33%2/6
not $@ and $ver->{"db"} ne $ver->{"schema"}
!ll&&!rl&&r
020
not $@ and $ver->{"db"} ne $ver->{"schema"}
!ll&&!rl&&r
010
MC/DC0%0/2
not $@ and $ver->{"db"} ne $ver->{"schema"}
not $@ $ver->{"db"} ne $ver->{"schema"}
MC/DC0%0/2
not $@ and $ver->{"db"} ne $ver->{"schema"}
not $@ $ver->{"db"} ne $ver->{"schema"}
Truth table33%1/3
not(A) and B
A= not $@B= $ver->{"db"} ne $ver->{"schema"}
ABresult
0X0
100
111
Truth table33%1/3
not(A) and B
A= not $@B= $ver->{"db"} ne $ver->{"schema"}
ABresult
0X0
100
111
136 0 warn "datasource '$datasource' out-of-date: db ($ver->{db}) vs. schema file ($ver->{schema})\n";
137 0 $db_outdated = 1;
138 }
139 }
140  
141 2 ▶ warn "please update db using: 'bin/updatedb --datasource=<datasource name>'\n"
Branch: 2 branches
BranchTrueFalseTotal
if $db_outdated 0 1 1
if $db_outdated 0 1 1
142 if $db_outdated;
143  
144 0 my $test_dir = $root->append ('t')->as_dir;
145
146 0 ▶ if (-d $test_dir) {
Branch: 2 branches
BranchTrueFalseTotal
if (-d $test_dir) 1 0 1
if (-d $test_dir) 1 0 1
147 0 ▶ $test_dir->scan_tree (sub {
Subroutine __ANON__: not called CC=3 SCAR=16.2
148 0 ▶ my $file = shift;
Subroutine __ANON__: called CC=3 SCAR=16.2
149
150 0 ▶ return 1
Branch: 2 branches
BranchTrueFalseTotal
if $file->type eq "dir" 0 1 1
if $file->type eq "dir" 0 0 0
151 if $file->type eq 'dir';
152
153 0 ▶ if ($file =~ /\.(?:t|pl)$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($file =~ /\.(?:t|pl)$/) 1 0 1
if ($file =~ /\.(?:t|pl)$/) 0 0 0
154 0 my $path = $file->abs_path;
155
156 0 run_script ("$^X $includes $path", $path);
157 }
158 1 });
159 }
160
161 1 print "OK\n";
162
163 1 return $pack;
164 }
165  
166 6 1;
« lib/Project/Easy/DB.pm ↑ Summary lib/Project/Easy.pm »