| 1 | package App::Bernard::Magic::Single; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use File::MimeInfo; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use File::Slurp; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 9 | 1 | return bless {}; | |||||||||||||||||||||||||||||||
| 10 | } | ||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | sub package_from_filetype { | ||||||||||||||||||||||||||||||
|
Subroutine
package_from_filetype: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 13 | 1 | my ($filename) = @_; | |||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | 1 | my $mimetype = mimetype($filename); | |||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | 1 | my $pkg = $mimetype; | |||||||||||||||||||||||||||||||
| 18 | 1 | $pkg =~ s/\b(.)/\U$1/g; | |||||||||||||||||||||||||||||||
| 19 | 1 | $pkg =~ s/[^a-z]//gi; | |||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | 1 | return ("App::Bernard::Filetype::$pkg", $mimetype); | |||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | sub replace_inplace { | ||||||||||||||||||||||||||||||
|
Subroutine
replace_inplace: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | 0 | my ($settings) = @_; | |||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | if ($settings->{'inplace'}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 29 | 0 | rename $settings->{'output'}, $settings->{'input'}; | |||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | sub handle { | ||||||||||||||||||||||||||||||
|
Subroutine
handle: called CC=11 SCAR=38.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | 1 | my ($self, $settings) = @_; | |||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | 1 | ▶ | if ($settings->{'output'}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | open OUTPUT, ">$settings->{'output'}" | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 39 | or die "Can't open $settings->{'output'}: $!"; | ||||||||||||||||||||||||||||||||
| 40 | 0 | binmode OUTPUT, ":utf8"; | |||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | $settings->{'print'} = sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 44 | 0 | my ($text) = @_; | |||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | if ($settings->{'output'}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 47 | 0 | print OUTPUT $text; | |||||||||||||||||||||||||||||||
| 48 | } else { | ||||||||||||||||||||||||||||||||
| 49 | 0 | print $text; | |||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||
| 51 | 1 | }; | |||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | 1 | ▶ | die "File $settings->{'input'} does not exist\n" unless -e $settings->{'input'}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 54 | 1 | my ($pkg, $mimetype) = package_from_filetype($settings->{'input'}); | |||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | # TODO: Probably should query the package | ||||||||||||||||||||||||||||||||
| 57 | # about whether it accepts --in-place | ||||||||||||||||||||||||||||||||
| 58 | die "--in-place can only be used with .po files" | ||||||||||||||||||||||||||||||||
| 59 | 1 | ▶ | if $settings->{'inplace'} && $mimetype ne 'text/x-gettext-translation'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$settings->{"inplace"} and $mimetype ne "text/x-gettext-translation"
MC/DC0%0/2
$settings->{"inplace"} and $mimetype ne "text/x-gettext-translation"
$settings->{"inplace"}
$mimetype ne "text/x-gettext-translation"
Truth table33%1/3
A and B
A= $settings->{"inplace"}B= $mimetype ne "text/x-gettext-translation"
| |||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | 1 | eval { | |||||||||||||||||||||||||||||||
| 62 | # okay, attempt to load the handler package | ||||||||||||||||||||||||||||||||
| 63 | 1 | my $filename = $pkg; | |||||||||||||||||||||||||||||||
| 64 | 1 | $filename =~ s!::!/!g; | |||||||||||||||||||||||||||||||
| 65 | 1 | require "$filename.pm"; | |||||||||||||||||||||||||||||||
| 66 | }; | ||||||||||||||||||||||||||||||||
| 67 | 1 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 68 | 1 | die "$settings->{'file'} is of type $mimetype, which we cannot handle.\n"; | |||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | 0 | $pkg->handle(scalar(read_file($settings->{'input'})), | |||||||||||||||||||||||||||||||
| 72 | $settings); | ||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | close OUTPUT | ||||||||||||||||||||||||||||||||
| 75 | or die "Can't close $settings->{'output'}: $!" | ||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | if $settings->{'output'}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$settings->{'output'} && (close OUTPUT || die("Can't close $settings->{'output'}: $!"))
close OUTPUT or die qq[Can't close $settings->{"output"}: $!]
MC/DC0%0/2
$settings->{'output'} && (close OUTPUT || die("Can't close $settings->{'output'}: $!"))
$settings->{'output'}
close OUTPUT
Truth table0%0/3
A && B
A= $settings->{'output'}B= close OUTPUT
| |||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if ($settings->{'check'}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 79 | 0 | my $result = | |||||||||||||||||||||||||||||||
| 80 | system "msgfmt -c $settings->{'output'} -o /dev/null"; | ||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | if ($result != 0) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 83 | 0 | die "Check failed; aborting\n"; | |||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | 0 | replace_inplace($settings); | |||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||
| 90 | 1 | 1; | |||||||||||||||||||||||||||||||