File Coverage

blib/lib/PDF/API2/Basic/PDF/Literal.pm
Criterion Covered Total %
statement 18 54 33.3
branch 0 20 0.0
condition 0 3 0.0
subroutine 6 9 66.6
pod 3 3 100.0
total 27 89 30.3


line stmt bran cond sub pod time code
1             # Literal PDF Object for Dirty Hacks ...
2             package PDF::API2::Basic::PDF::Literal;
3              
4 41     41   284 use base 'PDF::API2::Basic::PDF::Objind';
  41         87  
  41         3924  
5              
6 41     41   264 use strict;
  41         83  
  41         1557  
7              
8             our $VERSION = '2.045'; # VERSION
9              
10 41     41   228 use PDF::API2::Basic::PDF::Filter;
  41         91  
  41         1088  
11 41     41   247 use PDF::API2::Basic::PDF::Name;
  41         103  
  41         1235  
12 41     41   241 use Scalar::Util qw(blessed);
  41         101  
  41         2405  
13              
14 41     41   291 no warnings qw[ deprecated recursion uninitialized ];
  41         87  
  41         26494  
15              
16             sub new
17             {
18 0     0 1   my ($class, @opts) = @_;
19 0           my ($self);
20              
21 0 0         $class = ref $class if ref $class;
22 0           $self = $class->SUPER::new(@_);
23 0           $self->{' realised'} = 1;
24 0 0         if(scalar @opts > 1) {
    0          
25 0           $self->{-isdict}=1;
26 0           my %opt=@opts;
27 0           foreach my $k (keys %opt) {
28 0           $self->{$k} = $opt{$k};
29             }
30             } elsif(scalar @opts == 1) {
31 0           $self->{-literal}=$opts[0];
32             }
33 0           return $self;
34             }
35              
36             sub outobjdeep
37             {
38 0     0 1   my ($self, $fh, $pdf) = @_;
39 0 0         if($self->{-isdict})
40             {
41 0 0         if(defined $self->{' stream'})
42             {
43 0           $self->{Length} = length($self->{' stream'}) + 1;
44             }
45             else
46             {
47 0           delete $self->{Length};
48             }
49 0           $fh->print("<< ");
50 0           foreach my $k (sort keys %{$self})
  0            
51             {
52 0 0         next if($k=~m|^[ \-]|o);
53 0           $fh->print('/'.PDF::API2::Basic::PDF::Name::string_to_name($k).' ');
54 0 0 0       if(ref($self->{$k}) eq 'ARRAY')
    0          
    0          
55             {
56 0           $fh->print('['.join(' ',@{$self->{$k}})."]\n");
  0            
57             }
58             elsif(ref($self->{$k}) eq 'HASH')
59             {
60 0           $fh->print('<<'.join(' ', map { '/'.PDF::API2::Basic::PDF::Name::string_to_name($_).' '.$self->{$k}->{$_} } sort keys %{$self->{$k}})." >>\n");
  0            
  0            
61             }
62             elsif(blessed($self->{$k}) and $self->{$k}->can('outobj'))
63             {
64 0           $self->{$k}->outobj($fh, $pdf);
65 0           $fh->print("\n");
66             }
67             else
68             {
69 0           $fh->print("$self->{$k}\n");
70             }
71             }
72 0           $fh->print(">>\n");
73 0 0         if(defined $self->{' stream'})
74             {
75 0           $fh->print("stream\n$self->{' stream'}\nendstream"); # next is endobj which has the final cr
76             }
77             }
78             else
79             {
80 0           $fh->print($self->{-literal}); # next is endobj which has the final cr
81             }
82             }
83              
84             sub val
85 0     0 1   { $_[0]; }
86              
87             1;