File Coverage

blib/lib/PDF/Builder/Resource.pm
Criterion Covered Total %
statement 30 30 100.0
branch 4 6 66.6
condition 4 6 66.6
subroutine 8 8 100.0
pod 2 2 100.0
total 48 52 92.3


line stmt bran cond sub pod time code
1             package PDF::Builder::Resource;
2              
3 39     39   404 use base 'PDF::Builder::Basic::PDF::Dict';
  39         93  
  39         6812  
4              
5 39     39   320 use strict;
  39         125  
  39         1478  
6 39     39   205 use warnings;
  39         143  
  39         4674  
7              
8             our $VERSION = '3.028'; # VERSION
9             our $LAST_UPDATE = '3.027'; # manually update whenever code is changed
10              
11 39     39   259 use PDF::Builder::Util qw(pdfkey);
  39         120  
  39         4932  
12 39     39   286 use PDF::Builder::Basic::PDF::Utils; # PDFName
  39         93  
  39         4406  
13              
14 39     39   432 use Scalar::Util qw(weaken);
  39         87  
  39         12792  
15              
16             =head1 NAME
17              
18             PDF::Builder::Resource - Base class for PDF resources
19              
20             Inherits from L<PDF::Builder::Basic::PDF::Dict>
21              
22             =head1 METHODS
23              
24             =head2 new
25              
26             $resource = PDF::Builder::Resource->new($pdf, $name)
27              
28             =over
29              
30             Returns a resource object.
31              
32             =back
33              
34             =cut
35              
36             sub new {
37 68     68 1 249 my ($class, $pdf, $name) = @_;
38              
39 68 50       252 $class = ref($class) if ref($class);
40              
41 68         566 my $self = $class->SUPER::new();
42              
43 68 50       531 $pdf->new_obj($self) unless $self->is_obj($pdf);
44              
45 68   66     517 $self->name($name or pdfkey());
46              
47 68         192 $self->{' apipdf'} = $pdf;
48 68         197 weaken $self->{' apipdf'};
49              
50 68         279 return $self;
51             }
52              
53             # Note: new_api() removed in favor of new():
54             # new_api($api, ...) replace with new($api->{'pdf'}, ...)
55              
56             =head2 name
57              
58             $name = $resource->name() # Get
59              
60             $resource->name($name) # Set
61              
62             =over
63              
64             Get or set the name of the resource.
65              
66             =back
67              
68             =cut
69              
70             sub name {
71 130     130 1 299 my $self = shift @_;
72 130 100 66     681 if (scalar @_ and defined $_[0]) {
73 68         385 $self->{'Name'} = PDFName($_[0]);
74             }
75 130         721 return $self->{'Name'}->val();
76             }
77              
78             #sub outobjdeep {
79             # my ($self, $fh, $pdf, %options) = @_;
80             #
81             # delete $self->{' api'};
82             # delete $self->{' apipdf'};
83             # return $self->SUPER::outobjdeep($fh, $pdf, %options);
84             #}
85              
86             1;