File Coverage

blib/lib/PDF/Builder/Basic/PDF/Literal.pm
Criterion Covered Total %
statement 18 55 32.7
branch 0 20 0.0
condition 0 3 0.0
subroutine 6 9 66.6
pod 3 3 100.0
total 27 90 30.0


line stmt bran cond sub pod time code
1             # Literal PDF Object for Dirty Hacks ...
2             package PDF::Builder::Basic::PDF::Literal;
3              
4 41     41   284 use base 'PDF::Builder::Basic::PDF::Objind';
  41         116  
  41         4031  
5              
6 41     41   289 use strict;
  41         90  
  41         858  
7 41     41   194 use warnings;
  41         85  
  41         2310  
8              
9             our $VERSION = '3.025'; # VERSION
10             our $LAST_UPDATE = '3.024'; # manually update whenever code is changed
11              
12 41     41   275 use PDF::Builder::Basic::PDF::Filter;
  41         111  
  41         1306  
13 41     41   277 use PDF::Builder::Basic::PDF::Name;
  41         119  
  41         1219  
14 41     41   276 use Scalar::Util qw(blessed);
  41         150  
  41         26642  
15              
16             =head1 NAME
17              
18             PDF::Builder::Basic::PDF::Literal - Literal PDF Object. Inherits from L
19              
20             =cut
21              
22             sub new {
23 0     0 1   my ($class, @opts) = @_;
24 0           my ($self);
25              
26 0 0         $class = ref($class) if ref($class);
27 0           $self = $class->SUPER::new(@_);
28 0           $self->{' realised'} = 1;
29 0 0         if (scalar @opts > 1) {
    0          
30 0           $self->{'-isdict'} = 1;
31 0           my %opt = @opts;
32 0           foreach my $k (keys %opt) {
33 0           $self->{$k} = $opt{$k};
34             }
35             } elsif (scalar @opts == 1) {
36 0           $self->{'-literal'} = $opts[0];
37             }
38 0           return $self;
39             }
40              
41             sub outobjdeep {
42 0     0 1   my ($self, $fh, $pdf) = @_;
43 0 0         if ($self->{'-isdict'}) {
44 0 0         if (defined $self->{' stream'}) {
45 0           $self->{'Length'} = length($self->{' stream'}) + 1;
46             } else {
47 0           delete $self->{'Length'};
48             }
49 0           $fh->print("<< ");
50 0           foreach my $k (sort keys %{$self}) {
  0            
51 0 0         next if $k=~m|^[ \-]|o;
52 0           $fh->print('/'.PDF::Builder::Basic::PDF::Name::string_to_name($k).' ');
53 0 0 0       if (ref($self->{$k}) eq 'ARRAY') {
    0          
    0          
54 0           $fh->print('[' . join(' ',@{$self->{$k}}) . "]\n");
  0            
55             } elsif (ref($self->{$k}) eq 'HASH') {
56             $fh->print('<<' .
57             join(' ', map { '/'.PDF::Builder::Basic::PDF::Name::string_to_name($_) .
58 0           ' ' . $self->{$k}->{$_} } sort keys %{$self->{$k}}) .
  0            
  0            
59             " >>\n");
60             } elsif (blessed($self->{$k}) and $self->{$k}->can('outobj')) {
61 0           $self->{$k}->outobj($fh, $pdf);
62 0           $fh->print("\n");
63             } else {
64 0           $fh->print("$self->{$k}\n");
65             }
66             }
67 0           $fh->print(">>\n");
68 0 0         if (defined $self->{' stream'}) {
69 0           $fh->print("stream\n$self->{' stream'}\nendstream"); # next is endobj which has the final cr
70             }
71             } else {
72 0           $fh->print($self->{'-literal'}); # next is endobj which has the final cr
73             }
74 0           return;
75             }
76              
77 0     0 1   sub val { return $_[0]; }
78              
79             1;