| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 35 | 0 | ▶ | my $output_directory = delete $options{ output_directory } // '.'; | ||||||||||||||||||||||||||
|
Condition0%0/2
delete $options{"output_directory"} // "."
MC/DC0%0/1
delete $options{"output_directory"} // "."
delete $options{"output_directory"}
Truth table0%0/2
A
A= delete $options{"output_directory"}
| |||||||||||||||||||||||||||||
| 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)"
MC/DC0%0/1
$options{"encoding"} // ":raw:encoding(UTF-8)"
$options{"encoding"}
Truth table0%0/2
A
A= $options{"encoding"}
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | my $content = ''; | |||||||||||||||||||||||||||
| 43 | 0 | ▶ | if( -f $filename ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if( $keep_existing ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | return if $keep_existing and not $force; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$keep_existing and not $force
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
| |||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | open my $fh, "<$encoding", $filename | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 55 | 0 | make_path( dirname $filename ); # just to be sure | |||||||||||||||||||||||||||
| 56 | 0 | ▶ | if( open my $fh, ">$encoding", $filename ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||