| 1 | package App::PNGCrush; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | our $VERSION = '0.003'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Proc::Reliable; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Devel::TakeHashArgs; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use base 'Class::Data::Accessor'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 2 | my %Valid_Options = qw( | |||||||||||||||||||||||||||
| 14 | already_size -already | ||||||||||||||||||||||||||||
| 15 | bit_depth -bit_depth | ||||||||||||||||||||||||||||
| 16 | background -bkgd | ||||||||||||||||||||||||||||
| 17 | brute_force -brute | ||||||||||||||||||||||||||||
| 18 | color_type -c | ||||||||||||||||||||||||||||
| 19 | color_counting -cc | ||||||||||||||||||||||||||||
| 20 | output_dir -d | ||||||||||||||||||||||||||||
| 21 | double_image_gamma -dou | ||||||||||||||||||||||||||||
| 22 | output_extension -e | ||||||||||||||||||||||||||||
| 23 | filter -f | ||||||||||||||||||||||||||||
| 24 | fix_fatal -fix | ||||||||||||||||||||||||||||
| 25 | output_force -force | ||||||||||||||||||||||||||||
| 26 | gamma -g | ||||||||||||||||||||||||||||
| 27 | itxt -itxt | ||||||||||||||||||||||||||||
| 28 | level -l | ||||||||||||||||||||||||||||
| 29 | method -m | ||||||||||||||||||||||||||||
| 30 | maximum_idat -max | ||||||||||||||||||||||||||||
| 31 | no_output -n | ||||||||||||||||||||||||||||
| 32 | no_color_counting -no_cc | ||||||||||||||||||||||||||||
| 33 | plte_length -plte_len | ||||||||||||||||||||||||||||
| 34 | remove -rem | ||||||||||||||||||||||||||||
| 35 | replace_gamma -replace_gamma | ||||||||||||||||||||||||||||
| 36 | resolution -res | ||||||||||||||||||||||||||||
| 37 | save_unknown -save | ||||||||||||||||||||||||||||
| 38 | srgb -srgb | ||||||||||||||||||||||||||||
| 39 | text -text | ||||||||||||||||||||||||||||
| 40 | transparency -trns | ||||||||||||||||||||||||||||
| 41 | window_size -w | ||||||||||||||||||||||||||||
| 42 | strategy -z | ||||||||||||||||||||||||||||
| 43 | insert_ztxt -zitxt | ||||||||||||||||||||||||||||
| 44 | ztxt -ztxt | ||||||||||||||||||||||||||||
| 45 | verbose -v | ||||||||||||||||||||||||||||
| 46 | ); | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 2 | my %No_Arg_Options = map { $_ => 1 } qw( | |||||||||||||||||||||||||||
| 49 | brute_force | ||||||||||||||||||||||||||||
| 50 | color_counting | ||||||||||||||||||||||||||||
| 51 | double_image_gamma | ||||||||||||||||||||||||||||
| 52 | fix_fatal | ||||||||||||||||||||||||||||
| 53 | output_force | ||||||||||||||||||||||||||||
| 54 | no_output | ||||||||||||||||||||||||||||
| 55 | no_color_counting | ||||||||||||||||||||||||||||
| 56 | save_unknown | ||||||||||||||||||||||||||||
| 57 | verbose | ||||||||||||||||||||||||||||
| 58 | ); | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 2 | __PACKAGE__->mk_classaccessors ( | |||||||||||||||||||||||||||
| 61 | qw( proc error results ), | ||||||||||||||||||||||||||||
| 62 | keys %Valid_Options | ||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 66 | 1 | my $self = bless {}, shift; | |||||||||||||||||||||||||||
| 67 | 1 | ▶ | get_args_as_hash( \@_, \my %args, { maxtime => 300 } ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | or croak $@; | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 1 | my $proc = Proc::Reliable->new; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 1 | $proc->$_( $args{$_} ) for keys %args; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 1 | $self->proc( $proc ); | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 1 | return $self; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||
| 80 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 81 | 0 | my $in = shift; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | get_args_as_hash( \@_, \ my %args, { in => $in }, ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | or croak $@; | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | $self->$_(undef) for qw(error results); | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | my @options = exists $args{opts} | ||||||||||||||||||||||||||||
| 89 | 0 | ▶ | ? @{ $args{opts} } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | : $self->_make_options; | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 0 | my $proc = $self->proc; | |||||||||||||||||||||||||||
| 93 | 0 | my %out; | |||||||||||||||||||||||||||
| 94 | 0 | @out{ qw(stdout stderr status msg) } | |||||||||||||||||||||||||||
| 95 | = $proc->run( [ 'pngcrush', @options, $in ] ); | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | return $self->_set_error("Proc::Reliable error: $out{error}") | ||||||||||||||||||||||||||||
| 98 | 0 | ▶ | if defined $out{error}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | return $self->_set_error("File $in does not seem to exist") | ||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if $out{stdout} =~ /Could not find file: \Q$in/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | @out{ qw(idat size) } = $out{stdout} | ||||||||||||||||||||||||||||
| 104 | 0 | =~ /\(([\d.]+)% IDAT reduction\).+?\(([\d.]+)% filesize reduction\)/s; | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | $out{idat} = 0 | ||||||||||||||||||||||||||||
| 107 | if not defined $out{idat} | ||||||||||||||||||||||||||||
| 108 | 0 | ▶ | and $out{stdout} =~ /\Q(no IDAT change)/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $out{"idat"} and $out{"stdout"} =~ /\(no\ IDAT\ change\)/
MC/DC0%0/2
not defined $out{"idat"} and $out{"stdout"} =~ /\(no\ IDAT\ change\)/
not defined $out{"idat"}
$out{"stdout"} =~ /\(no\ IDAT\ change\)/
Truth table0%0/3
not(A) and B
A= not defined $out{"idat"}B= $out{"stdout"} =~ /\(no\ IDAT\ change\)/
| |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | $out{size} = 0 | ||||||||||||||||||||||||||||
| 111 | if not defined $out{size} | ||||||||||||||||||||||||||||
| 112 | 0 | ▶ | and $out{stdout} =~ /\Q(no filesize change)/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $out{"size"} and $out{"stdout"} =~ /\(no\ filesize\ change\)/
MC/DC0%0/2
not defined $out{"size"} and $out{"stdout"} =~ /\(no\ filesize\ change\)/
not defined $out{"size"}
$out{"stdout"} =~ /\(no\ filesize\ change\)/
Truth table0%0/3
not(A) and B
A= not defined $out{"size"}B= $out{"stdout"} =~ /\(no\ filesize\ change\)/
| |||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | @{ $out{cpu} }{ qw(total decoding encoding other) } = $out{stdout} | |||||||||||||||||||||||||||
| 115 | 0 | =~ /CPU \s time \s used \s = \s ([\d.]+) \s seconds \s | |||||||||||||||||||||||||||
| 116 | \(decoding \s ([\d.]+), \s+ | ||||||||||||||||||||||||||||
| 117 | encoding \s ([\d.]+), \s other \s ([\d.]+) \s seconds\) | ||||||||||||||||||||||||||||
| 118 | /x; | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | ( $out{total_idat_length} ) = $out{stdout} | ||||||||||||||||||||||||||||
| 121 | 0 | =~ /Total length of data found in IDAT chunks\s+=\s+([\d.]+)/; | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | return $self->results( \%out ); | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 0 | ▶ | sub set_options { | ||||||||||||||||||||||||||
|
Subroutine
set_options: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 127 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 128 | 0 | ▶ | get_args_as_hash( \@_, \my %args, {}, [], [ %Valid_Options ] ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | or croak $@; | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | $self->reset_options; | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 0 | keys %args; | |||||||||||||||||||||||||||
| 134 | 0 | my %shell_args = reverse %Valid_Options; | |||||||||||||||||||||||||||
| 135 | 0 | ▶ | while ( my ( $key, $value ) = each %args ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | $key = $shell_args{$key} | ||||||||||||||||||||||||||||
| 137 | 0 | ▶ | unless exists $Valid_Options{$key}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 0 | $self->$key( $value ); | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 0 | return 1; | |||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 0 | ▶ | sub reset_options { | ||||||||||||||||||||||||||
|
Subroutine
reset_options: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 146 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 0 | $self->$_(undef) for keys %Valid_Options; | |||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 0 | return 1; | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 0 | ▶ | sub _make_options { | ||||||||||||||||||||||||||
|
Subroutine
_make_options: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 154 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 0 | my @options; | |||||||||||||||||||||||||||
| 157 | 0 | for my $opt ( keys %Valid_Options ) { | |||||||||||||||||||||||||||
| 158 | 0 | my $value = $self->$opt; | |||||||||||||||||||||||||||
| 159 | next | ||||||||||||||||||||||||||||
| 160 | 0 | ▶ | unless defined $value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 0 | ▶ | if ( ref $value eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | 0 | ▶ | if ( $opt eq 'verbose' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | 0 | push @options, ('-v') x @$value; | |||||||||||||||||||||||||||
| 165 | 0 | next; | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | 0 | push @options, map { $Valid_Options{$opt} => $_ } @$value; | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | else { | ||||||||||||||||||||||||||||
| 170 | push @options, $Valid_Options{$opt}, | ||||||||||||||||||||||||||||
| 171 | 0 | ▶ | exists $No_Arg_Options{$opt} ? () : $value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | 0 | return @options; | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 0 | ▶ | sub _set_error { | ||||||||||||||||||||||||||
|
Subroutine
_set_error: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 178 | 0 | my ( $self, $error ) = @_; | |||||||||||||||||||||||||||
| 179 | 0 | $self->error($error); | |||||||||||||||||||||||||||
| 180 | 0 | return; | |||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 2 | 1; | |||||||||||||||||||||||||||
| 184 | __END__ | ||||||||||||||||||||||||||||