PerlGenerator/Utils.pm

filter: Statementstmt 46.3% 19 / 41 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 75.0% 6 / 8 Podpod 50.0% 1 / 2 totaltotal 33.3% 26 / 78 CC 12 SCAR 43.5
CC
12
Cov
30%
update_file
132.0
tidy
6.0
BEGIN
1.0
CRAP 77.4
↑ Summary PerlGenerator.pm »
1 package OpenAPI::PerlGenerator::Utils 0.02;
2 3 ▶use 5.020;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Perl::Tidy;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use File::Path 'make_path';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 our @EXPORT_OK = (qw(tidy update_file));
11  
12 0 ▶sub tidy( $source ) {
Subroutine tidy: not called CC=2 SCAR=17.9
Pod undocumented
13 0 my $formatted = $source;
14 0 ▶ Perl::Tidy::perltidy(
Branch: 1 branch
BranchTrueFalseTotal
Perl::Tidy::perltidy("source", \$source, "destination", \$formatted, "argv", ["--no-memoize"]) or $source = $formatted 0 0 0
15 source => \$source,
16 destination => \$formatted,
17 argv => [ '--no-memoize' ],
18 ) or $source = $formatted;
19 0 return $formatted;
20 }
21  
22 =head2 C<< update_file >>
23  
24 update_file( filename => $package->{filename},
25 output_directory => $output_directory,
26 keep_existing => (!!($package->{package} =~ /\bClient\z/)),
27 content => $package->{source},
28 );
29  
30 =cut
31  
32 0 ▶sub update_file( %options ) {
Subroutine update_file: not called CC=11 SCAR=48.8
Pod documented
33 my $filename = delete $options{ filename }
34 0 ▶ or die "Need a filename to create/update";
Branch: 1 branch
BranchTrueFalseTotal
my $filename = delete $options{"filename"} or die "Need a filename to create/update" 0 0 0
35 0 ▶ my $output_directory = delete $options{ output_directory } // '.';
Condition0%0/2
delete $options{"output_directory"} // "."
l!l
00
MC/DC0%0/1
delete $options{"output_directory"} // "."
delete $options{"output_directory"}
Truth table0%0/2
A
A= delete $options{"output_directory"}
Aresult
11
00
36 0 my $force = delete $options{ force };
37 0 $filename = "$output_directory/$filename";
38 0 my $new_content = delete $options{ content };
39 0 my $keep_existing = $options{ keep_existing };
40 0 ▶ my $encoding = $options{ encoding } // ':raw:encoding(UTF-8)';
Condition0%0/2
$options{"encoding"} // ":raw:encoding(UTF-8)"
l!l
00
MC/DC0%0/1
$options{"encoding"} // ":raw:encoding(UTF-8)"
$options{"encoding"}
Truth table0%0/2
A
A= $options{"encoding"}
Aresult
11
00
41  
42 0 my $content = '';
43 0 ▶ if( -f $filename ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $filename) 0 0 0
44 0 ▶ if( $keep_existing ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($keep_existing) 0 0 0
45 0 ▶ return if $keep_existing and not $force;
Branch: 1 branch
BranchTrueFalseTotal
if $keep_existing and not $force 0 0 0
Condition0%0/3
$keep_existing and not $force
!ll&&!rl&&r
000
MC/DC0%0/2
$keep_existing and not $force
$keep_existing not $force
Truth table0%0/3
A and not(B)
A= $keep_existingB= not $force
ABresult
0X0
100
111
46 }
47  
48 0 ▶ open my $fh, "<$encoding", $filename
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<$encoding", $filename or die "Couldn't read '${filename}': $!" 0 0 0
49 or die "Couldn't read '$filename': $!";
50 0 local $/;
51 0 $content = <$fh>;
52 };
53  
54 0 ▶ if( $content ne $new_content ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content ne $new_content) 0 0 0
55 0 make_path( dirname $filename ); # just to be sure
56 0 ▶ if( open my $fh, ">$encoding", $filename ) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, ">$encoding", $filename) { } 0 0 0
57 0 print $fh $new_content;
58 } else {
59 0 warn "Couldn't (re)write '$filename': $!";
60 };
61 };
62 }
63  
64 3 1;
65 __END__
↑ Summary PerlGenerator.pm »