in reply to Choosing namespace/name for (my first) CPAN module which is a sub-class of a well-known distribution

Back in business after distraction. Tutorials and guides demand tests. Stealing parent's tests doesn't look good (gonna do it anyway), so I'll write something for added features. How to test whether "no slurping" mode is indeed functional? Is what follows an overkill? Are there blunders, can it be improved? Have I overseen something on CPAN?

Btw, PerlIO::via docs leave a few things to be desired. PUSHED is said to return "an object or the class". "Class" what? I can only satisfy it with blessed whatever, even as ridiculous as below. READ's arg is said to be "$buffer", but then I only succeeded with not very nice direct access to @_ element (won't Perl::Critic drop unconscious about it?). And using package as written as e.g. io layer and then reading with diamond operator (not related to my tests) generates random length strings, very weird. Perhaps it could be mentioned that without FILL defined (READ only) the readline is unusable? It's strange that a few core and CPAN modules I checked all work through FILL. No one does READ.

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
  • Comment on Re: Choosing namespace/name for (my first) CPAN module which is a sub-class of a well-known distribution
  • Select or Download Code