App-PNGCrush

 view release on metacpan or  search on metacpan

lib/App/PNGCrush.pm  view on Meta::CPAN

for suggestions.

=head1 CONSTRUCTOR

=head2 C<new>

    my $crush = App::PNGCrush->new;

    my $crush = App::PNGCrush->new( max_time => 300 );

Creates a new App::PNGCrush object. Arguments are optional and passed
as key/value pairs with keys being L<Proc::Reliable> methods and values
being the values for those methods, here you can set some options
controlling how C<pngcrush> will be run. Generally, you'd worry only
about C<max_time> (which B<defaults> to C<300> seconds in C<App::PNGCrush>)
and set it to a higher value if you are about to process large images
with brute force.

=head1 METHODS

=head2 C<run>

    my $results_ref = $crush->run('pic.png')
        or die $crush->error;

    my $results_ref = $crush->run('pic.png', opts => [ qw(custom stuff) ] );

Instructs the object to run C<pngcrush>. The first argument is mandatory
and must be a filename which will be passed to C<pngcrush> as input file.
Takes one optional argument (so far), which is passed as key/value
pair; the key being C<opts> and value being an arrayref of custom options
you want to give to C<pngcrush> (those will bypass shell processing).
Generally the custom options option is in here "just in case" and B<you
are recommended to set options via individual methods or C<set_options()>
method (see below).>

Returns either C<undef> or an empty list (depending on the context)
if an error occurred and the reason for the error will be available via
C<error()> method. On success returns a hashref with the following
keys/values:

    $VAR1 = {
        'total_idat_length' => '1880',
        'cpu' => {
                    'decoding' => '0.010',
                    'other' => '0.050',
                    'total' => '0.210',
                    'encoding' => '0.150'
        },
        'stderr' => '',
        'status' => '0',
        'idat' => '0.80',
        'stdout' => '| pngcrush 1.6.4 .. blah blah full STDOUT here',
        'size' => '1.56'
    };

=head3 C<size>

    { 'size' => '1.56', }

The C<size> key will contain percentage of filesize reduction.

=head3 C<idat>

    { 'idat' => '0.80', }

The C<idat> key will contain the percentage of IDAT size reduction.

=head3 C<total_idat_length>

    { 'total_idat_length' => '1880', }

The C<total_idat_length> key will contain total length of data found in
IDAT chunks.

=head3 C<cpu>

    'cpu' => {
        'decoding' => '0.010',
        'other' => '0.050',
        'total' => '0.210',
        'encoding' => '0.150'
    },

The C<cpu> key will contain a hashref with with four keys:
C<total>, C<decoding>, C<other> and C<encoding> with values being
number of seconds it took to process.

=head3 C<stderr>

    { 'stderr' => '', }

The C<stderr> key will contain any collected data from STDERR while
C<pngcrush> was running.

=head3 C<stdout>

    { 'stdout' => '| pngcrush 1.6.4 .. blah blah full STDOUT here', }

The C<stdout> key will contain any collected data from STDOUT while
C<pngcrush> was running.

=head3 C<status>

    { 'status' => '0' }

The C<status> key will contain the exit code of C<pngcrush>.

=head2 C<error>

    my $ret_ref = $crush->run('some.png')
        or die $crush->error;

If C<run> failed it will return either C<undef> or an empty list depending
on the context and the reason for failure will be available via C<error()>
method. Takes no arguments, returns a human parsable error message
explaining why C<run> failed.

=head2 C<results>

    my $results_ref = $crush->results;

Must be called after a successful call to C<run()>. Takes no arguments,
returns the exact same hashref last call to C<run()> returned.

=head2 C<set_options>



( run in 2.841 seconds using v1.01-cache-2.11-cpan-81fc1098f69 )