use strict; use warnings; use feature 'say'; use Test::More; BEGIN { package Counter; use strict; use warnings; our $count; sub PUSHED { $count = 0; return bless \(1 + 1), 1 } sub READ { my ( undef, $buffer, $len, $fh ) = @_; my $bytes = read $fh, $_[1], $len; $count += $bytes; return $bytes } sub BINMODE { 0 } sub SEEK { CORE::seek( $_[3], $_[1], $_[2] ) } } BEGIN { *CORE::GLOBAL::open = sub { splice @_, 1, 1, '<:raw:via(Counter)' if defined $_[1] and $_[1] eq '<'; &CORE::open } }; my $fname = 't/sample1.pdf'; die unless -e $fname; my $fsize = -s _; my $doc; use CAM::PDF; $doc = CAM::PDF-> new( $fname ); ok $doc, "file reading OK with CAM::PDF"; cmp_ok $Counter::count, '==', $fsize, "had to read $Counter::count bytes of total $fsize"; $doc-> getPageDimensions( 1 ); cmp_ok $Counter::count, '==', $fsize, "for info 1, cumulative read is OK: $Counter::count"; $doc-> getPageDimensions( 2 ); cmp_ok $Counter::count, '==', $fsize, "for info 2, cumulative read is OK: $Counter::count"; $doc-> cleansave; cmp_ok $Counter::count, '==', $fsize, "for all info, cumulative read is OK: $Counter::count"; # done_testing; ### you may wish to delete to the end of file for SSCCE, ### PDF::Manip is not released yet use lib 'lib'; use PDF::Manip; # $doc = PDF::Manip-> new( $fname ); # ok $doc, "file reading OK with PDF::Manip"; # cmp_ok $Counter::count, '==', $fsize, # "had to read $Counter::count bytes of total $fsize"; # $doc-> getPageDimensions( 1 ); # cmp_ok $Counter::count, '==', $fsize, # "for info 1, cumulative read is OK: $Counter::count"; # $doc-> getPageDimensions( 2 ); # cmp_ok $Counter::count, '==', $fsize, # "for info 2, cumulative read is OK: $Counter::count"; # $doc-> cleansave; # cmp_ok $Counter::count, '==', $fsize, # "for all info, cumulative read is OK: $Counter::count"; $doc = PDF::Manip-> new( $fname, { slurp => 0 }); ok $doc, "file reading OK with PDF::Manip (no slurping)"; cmp_ok $Counter::count, '<', $fsize, "had to read $Counter::count bytes of total $fsize"; $doc-> getPageDimensions( 1 ); cmp_ok $Counter::count, '<', $fsize, "for info 1, cumulative read is OK: $Counter::count"; $doc-> getPageDimensions( 2 ); cmp_ok $Counter::count, '<', $fsize, "for info 2, cumulative read is OK: $Counter::count"; $doc-> cleansave; cmp_ok $Counter::count, '>=', $fsize, "for all info, cumulative read is OK: $Counter::count"; done_testing; __END__ ok 1 - file reading OK with CAM::PDF ok 2 - had to read 621710 bytes of total 621710 ok 3 - for info 1, cumulative read is OK: 621710 ok 4 - for info 2, cumulative read is OK: 621710 ok 5 - for all info, cumulative read is OK: 621710 ok 6 - file reading OK with PDF::Manip (no slurping) ok 7 - had to read 3487 bytes of total 621710 ok 8 - for info 1, cumulative read is OK: 3593 ok 9 - for info 2, cumulative read is OK: 3702 ok 10 - for all info, cumulative read is OK: 623916 1..10