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 38     38   345 use base 'PDF::API2::Basic::PDF::Dict';
  38         92  
  38         4337  
4              
5 38     38   276 use strict;
  38         88  
  38         885  
6 38     38   207 use warnings;
  38         79  
  38         2654  
7              
8             our $VERSION = '2.043'; # VERSION
9              
10 38     38   281 use PDF::API2::Util qw(pdfkey);
  38         109  
  38         3945  
11 38     38   296 use PDF::API2::Basic::PDF::Utils; # PDFName
  38         91  
  38         3390  
12              
13 38     38   271 use Scalar::Util qw(weaken);
  38         106  
  38         12833  
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 247 my ($class, $pdf, $name) = @_;
31 85 50       309 $class = ref($class) if ref($class);
32              
33 85         482 my $self = $class->SUPER::new();
34              
35 85 50       463 $pdf->new_obj($self) unless $self->is_obj($pdf);
36              
37 85   66     528 $self->name($name or pdfkey());
38              
39 85         216 $self->{' apipdf'} = $pdf;
40 85         432 weaken $self->{' apipdf'};
41              
42 85         263 return $self;
43             }
44              
45             # Deprecated (warning added in 2.031)
46             sub new_api {
47 1     1 0 26 my ($class, $api2, @options) = @_;
48 1         165 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         6 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 355 my $self = shift @_;
64 149 100 66     643 if (scalar @_ and defined $_[0]) {
65 85         409 $self->{'Name'} = PDFName($_[0]);
66             }
67 149         610 return $self->{'Name'}->val();
68             }
69              
70             =back
71              
72             =cut
73              
74             1;