File Coverage

blib/lib/PDF/API2/Resource.pm
Criterion Covered Total %
statement 34 34 100.0
branch 4 6 66.6
condition 4 6 66.6
subroutine 9 9 100.0
pod 2 3 66.6
total 53 58 91.3


line stmt bran cond sub pod time code
1             package PDF::API2::Resource;
2              
3 39     39   323 use base 'PDF::API2::Basic::PDF::Dict';
  39         92  
  39         4193  
4              
5 39     39   255 use strict;
  39         100  
  39         795  
6 39     39   201 use warnings;
  39         95  
  39         2368  
7              
8             our $VERSION = '2.045'; # VERSION
9              
10 39     39   275 use PDF::API2::Util qw(pdfkey);
  39         99  
  39         3392  
11 39     39   285 use PDF::API2::Basic::PDF::Utils; # PDFName
  39         126  
  39         3313  
12              
13 39     39   342 use Scalar::Util qw(weaken);
  39         94  
  39         11913  
14              
15             =head1 NAME
16              
17             PDF::API2::Resource - Base class for PDF resources
18              
19             =head1 METHODS
20              
21             =over
22              
23             =item $resource = PDF::API2::Resource->new($pdf, $name)
24              
25             Returns a resource object.
26              
27             =cut
28              
29             sub new {
30 85     85 1 210 my ($class, $pdf, $name) = @_;
31 85 50       232 $class = ref($class) if ref($class);
32              
33 85         401 my $self = $class->SUPER::new();
34              
35 85 50       407 $pdf->new_obj($self) unless $self->is_obj($pdf);
36              
37 85   66     521 $self->name($name or pdfkey());
38              
39 85         211 $self->{' apipdf'} = $pdf;
40 85         361 weaken $self->{' apipdf'};
41              
42 85         205 return $self;
43             }
44              
45             # Deprecated (warning added in 2.031)
46             sub new_api {
47 1     1 0 23 my ($class, $api2, @options) = @_;
48 1         218 warnings::warnif('deprecated', q{Call to deprecated method "new_api($api2, ...)". Replace with "new($api2->{'pdf'}, ...)"});
49              
50 1         10 my $resource = $class->new($api2->{'pdf'}, @options);
51 1         5 return $resource;
52             }
53              
54             =item $name = $resource->name()
55              
56             =item $resource->name($name)
57              
58             Get or set the name of the resource.
59              
60             =cut
61              
62             sub name {
63 149     149 1 322 my $self = shift @_;
64 149 100 66     612 if (scalar @_ and defined $_[0]) {
65 85         306 $self->{'Name'} = PDFName($_[0]);
66             }
67 149         555 return $self->{'Name'}->val();
68             }
69              
70             =back
71              
72             =cut
73              
74             1;