| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  |  | 
| 2 |  |  |  |  |  |  | package Test::PDF; | 
| 3 |  |  |  |  |  |  |  | 
| 4 | 3 |  |  | 3 |  | 73930 | use strict; | 
|  | 3 |  |  |  |  | 8 |  | 
|  | 3 |  |  |  |  | 111 |  | 
| 5 | 3 |  |  | 3 |  | 16 | use warnings; | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 131 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | our $VERSION = '0.01'; | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 3 |  |  | 3 |  | 24 | use Test::Builder (); | 
|  | 3 |  |  |  |  | 11 |  | 
|  | 3 |  |  |  |  | 51 |  | 
| 10 | 3 |  |  | 3 |  | 5461 | use Test::Deep    (); | 
|  | 3 |  |  |  |  | 56466 |  | 
|  | 3 |  |  |  |  | 102 |  | 
| 11 | 3 |  |  | 3 |  | 30 | use Scalar::Util 'blessed'; | 
|  | 3 |  |  |  |  | 8 |  | 
|  | 3 |  |  |  |  | 183 |  | 
| 12 | 3 |  |  | 3 |  | 5963 | use CAM::PDF; | 
|  | 3 |  |  |  |  | 173602 |  | 
|  | 3 |  |  |  |  | 1039 |  | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | require Exporter; | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | our @ISA    = qw(Exporter); | 
| 17 |  |  |  |  |  |  | our @EXPORT = qw(cmp_pdf); | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | my $Test = Test::Builder->new; | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | sub cmp_pdf ($$;$) { | 
| 22 | 5 |  |  | 5 | 1 | 10110 | my ($got, $expected, $message) = @_; | 
| 23 | 5 | 100 | 66 |  |  | 64 | unless (blessed($got) && $got->isa('CAM::PDF')) { | 
| 24 | 3 |  | 50 |  |  | 25 | $got = CAM::PDF->new($got) | 
| 25 |  |  |  |  |  |  | || die "Could not create CAM::PDF instance with : $got"; | 
| 26 |  |  |  |  |  |  | } | 
| 27 | 5 | 100 | 66 |  |  | 5514 | unless (blessed($expected) && $expected->isa('CAM::PDF')) { | 
| 28 | 3 |  | 50 |  |  | 14 | $expected = CAM::PDF->new($expected) | 
| 29 |  |  |  |  |  |  | || die "Could not create CAM::PDF instance with : $expected"; | 
| 30 |  |  |  |  |  |  | } | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | # if they dont have the same number of | 
| 33 |  |  |  |  |  |  | # pages, then they can't be "equal" so | 
| 34 |  |  |  |  |  |  | # we can short-circuit a potentially | 
| 35 |  |  |  |  |  |  | # long test here ... | 
| 36 | 5 | 50 |  |  |  | 4660 | unless ($got->numPages() == $expected->numPages()) { | 
| 37 | 0 |  |  |  |  | 0 | $Test->ok(0, $message); | 
| 38 | 0 |  |  |  |  | 0 | return; | 
| 39 |  |  |  |  |  |  | } | 
| 40 |  |  |  |  |  |  |  | 
| 41 | 5 |  |  |  |  | 53 | my $do_PDFs_match = 0; | 
| 42 | 5 |  |  |  |  | 15 | foreach my $page_num (1 .. $got->numPages()) { | 
| 43 | 5 |  |  |  |  | 44 | my $tree1 = $got->getPageContentTree($page_num, "verbose"); | 
| 44 | 5 |  |  |  |  | 453802 | my $tree2 = $expected->getPageContentTree($page_num, "verbose"); | 
| 45 | 5 | 100 |  |  |  | 38512 | if (Test::Deep::eq_deeply($tree1->{blocks}, $tree2->{blocks})) { | 
| 46 | 3 |  |  |  |  | 529712 | $do_PDFs_match = 1; | 
| 47 |  |  |  |  |  |  | } | 
| 48 |  |  |  |  |  |  | else { | 
| 49 |  |  |  |  |  |  | # exit the loop as soon as we | 
| 50 |  |  |  |  |  |  | # determine the PDFs do not match | 
| 51 | 2 |  |  |  |  | 23494 | $do_PDFs_match = 0; | 
| 52 | 2 |  |  |  |  | 276 | last; | 
| 53 |  |  |  |  |  |  | } | 
| 54 |  |  |  |  |  |  | } | 
| 55 |  |  |  |  |  |  |  | 
| 56 | 5 |  |  |  |  | 51 | $Test->ok($do_PDFs_match, $message); | 
| 57 |  |  |  |  |  |  | } | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | 1; | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | __END__ |