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 34     34   311 use base 'PDF::Builder::Basic::PDF::Dict';
  34         91  
  34         3883  
4              
5 34     34   255 use strict;
  34         84  
  34         846  
6 34     34   221 use warnings;
  34         85  
  34         2587  
7              
8             our $VERSION = '3.023'; # VERSION
9             our $LAST_UPDATE = '3.017'; # manually update whenever code is changed
10              
11 34     34   286 use PDF::Builder::Util qw(pdfkey);
  34         112  
  34         3609  
12 34     34   265 use PDF::Builder::Basic::PDF::Utils; # PDFName
  34         81  
  34         3071  
13              
14 34     34   256 use Scalar::Util qw(weaken);
  34         79  
  34         9390  
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 80     80 1 311 my ($class, $pdf, $name) = @_;
32              
33 80 50       305 $class = ref($class) if ref($class);
34              
35 80         682 my $self = $class->SUPER::new();
36              
37 80 50       544 $pdf->new_obj($self) unless $self->is_obj($pdf);
38              
39 80   66     592 $self->name($name or pdfkey());
40              
41 80         229 $self->{' apipdf'} = $pdf;
42 80         493 weaken $self->{' apipdf'};
43              
44 80         254 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()
51              
52             =item $resource->name($name)
53              
54             Get or set the name of the resource.
55              
56             =cut
57              
58             sub name {
59 138     138 1 379 my $self = shift @_;
60 138 100 66     726 if (scalar @_ and defined $_[0]) {
61 80         494 $self->{'Name'} = PDFName($_[0]);
62             }
63 138         714 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;