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

In reply to Re: Choosing namespace/name for (my first) CPAN module which is a sub-class of a well-known distribution by Anonymous Monk
in thread Choosing namespace/name for (my first) CPAN module which is a sub-class of a well-known distribution by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.