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 38     38   335 use base 'PDF::Builder::Basic::PDF::Dict';
  38         104  
  38         4523  
4              
5 38     38   301 use strict;
  38         113  
  38         1099  
6 38     38   209 use warnings;
  38         120  
  38         2848  
7              
8             our $VERSION = '3.025'; # VERSION
9             our $LAST_UPDATE = '3.024'; # manually update whenever code is changed
10              
11 38     38   331 use PDF::Builder::Util qw(pdfkey);
  38         109  
  38         3885  
12 38     38   294 use PDF::Builder::Basic::PDF::Utils; # PDFName
  38         100  
  38         3713  
13              
14 38     38   297 use Scalar::Util qw(weaken);
  38         110  
  38         10035  
15              
16             =head1 NAME
17              
18             PDF::Builder::Resource - Base class for PDF resources. Inherit from L
19              
20             =head1 METHODS
21              
22             =over
23              
24             =item $resource = PDF::Builder::Resource->new($pdf, $name)
25              
26             Returns a resource object.
27              
28             =cut
29              
30             sub new {
31 83     83 1 228 my ($class, $pdf, $name) = @_;
32              
33 83 50       251 $class = ref($class) if ref($class);
34              
35 83         417 my $self = $class->SUPER::new();
36              
37 83 50       432 $pdf->new_obj($self) unless $self->is_obj($pdf);
38              
39 83   66     576 $self->name($name or pdfkey());
40              
41 83         213 $self->{' apipdf'} = $pdf;
42 83         409 weaken $self->{' apipdf'};
43              
44 83         252 return $self;
45             }
46              
47             # Note: new_api() removed in favor of new():
48             # new_api($api, ...) replace with new($api->{'pdf'}, ...)
49              
50             =item $name = $resource->name() # Get
51              
52             =item $resource->name($name) # Set
53              
54             Get or set the name of the resource.
55              
56             =cut
57              
58             sub name {
59 145     145 1 303 my $self = shift @_;
60 145 100 66     634 if (scalar @_ and defined $_[0]) {
61 83         353 $self->{'Name'} = PDFName($_[0]);
62             }
63 145         588 return $self->{'Name'}->val();
64             }
65              
66             #sub outobjdeep {
67             # my ($self, $fh, $pdf, %options) = @_;
68             #
69             # delete $self->{' api'};
70             # delete $self->{' apipdf'};
71             # return $self->SUPER::outobjdeep($fh, $pdf, %options);
72             #}
73              
74             =back
75              
76             =cut
77              
78             1;