PDF/ImageTemplate.pm untested

filter: Statementstmt 0.0% 0 / 38 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 64 CC 2 SCAR 11.0
CC
2
Cov
0%
get_template_pdf
6.0
_selfupdate
2.0
BEGIN
2.0
CRAP 3.0
1 ## no critic(ErrorHandling::RequireCarping, Documentation::RequirePodAtEnd, Editor::RequireEmacsFileVariables)
2  
3 #######################################################################
4 # $URL: svn+ssh://equilibrious@equilibrious.net/home/equilibrious/svnrepos/chrisdolan/Fuse-PDF/lib/Fuse/PDF/ImageTemplate.pm $
5 # $Date: 2008-06-06 22:47:54 -0500 (Fri, 06 Jun 2008) $
6 # $Author: equilibrious $
7 # $Revision: 767 $
8 ########################################################################
9  
10 package Fuse::PDF::ImageTemplate;
11  
12 use warnings;
13 use strict;
14 use English qw(-no_match_vars);
15 use MIME::Base64 qw();
16 use CAM::PDF;
17  
18 our $VERSION = '0.09';
19  
20 my $content; # cache
21 sub get_template_pdf {
22 my ($pkg) = @_;
23  
24 if (!$content) {
25 $content = MIME::Base64::decode(do { local $RS = undef; <DATA>});
26 }
27 return CAM::PDF->new($content);
28 }
29  
30 sub _selfupdate {
31 my ($pkg, $source_file) = @_;
32  
33 my $pdf = CAM::PDF->new($source_file) or die $CAM::PDF::errstr; ## no critic(PackageVar)
34 my $pdfsrc = MIME::Base64::encode($pdf->{content});
35  
36 open my $ifh, '<', __FILE__ or die $OS_ERROR;
37 my $code = do {local $RS = undef; <$ifh> };
38 close $ifh or die $OS_ERROR;
39 $code =~ s/(^__DATA__\s*).* \z/$1$pdfsrc/xms;
40
41 open my $ofh, '>', __FILE__ or die $OS_ERROR;
42 print {$ofh} $code;
43 close $ofh or die $OS_ERROR;
44  
45 return;
46 }
47  
48 1;
49  
50 =pod
51  
52 =head1 NAME
53  
54 Fuse::PDF::ImageTemplate - [Internal] Carrier for the template PDF for images
55  
56 =head1 SYNOPSIS
57  
58 This is an internal package, not intended for general use.
59  
60 use Fuse::PDF::ImageTemplate;
61 my $pdf = Fuse::PDF::ImageTemplate->get_template_pdf();
62  
63 =head1 LICENSE
64  
65 Copyright 2007-2008 Chris Dolan, I<cdolan@cpan.org>
66  
67 This library is free software; you can redistribute it and/or modify it
68 under the same terms as Perl itself.
69  
70 =head1 DESCRIPTION
71  
72 A tiny, binary PDF is embedded in this source code. It is used to
73 wrap images for use in L<Fuse::PDF::ContentFS>.
74  
75 =head1 METHODS
76  
77 =over
78  
79 =item Fuse::PDF::ImageTemplate->get_template_pdf()
80  
81 Returns a new L<CAM::PDF> instance of the embedded template PDF.
82  
83 =back
84  
85 =head1 SEE ALSO
86  
87 L<Fuse::PDF::ContentFS>
88  
89 =head1 AUTHOR
90  
91 Chris Dolan, I<cdolan@cpan.org>
92  
93 =cut
94  
95 # The data below is generated by "perl image_template_update.PL" which
96 # invokes the _selfupdate() function above with the image_template.pdf
97 # as an argument. One can recreate the image_template.pdf by
98 # calling get_template_pdf()->output($filename)
99  
100 __DATA__