| 1 | use Renard::Incunabula::Common::Setup; | ||
| 2 | package Renard::Block::Format::PDF::InformationDictionary; | ||
| 3 | # ABSTRACT: represents the PDF document information dictionary | ||
| 4 | $Renard::Block::Format::PDF::InformationDictionary::VERSION = '0.005'; | ||
| 5 | use Moo; | ||
| 6 | use Renard::Incunabula::Common::Types qw(Maybe File InstanceOf Str HashRef ArrayRef); | ||
| 7 | use Renard::API::MuPDF::mutool; | ||
| 8 | |||
| 9 | has filename => ( | ||
| 10 | is => 'ro', | ||
| 11 | isa => File, | ||
| 12 | coerce => 1, | ||
| 13 | ); | ||
| 14 | |||
| 15 | has _object => ( | ||
| 16 | is => 'lazy', | ||
| 17 | isa => InstanceOf['Renard::API::MuPDF::mutool::ObjectParser'], | ||
| 18 | handles => { | ||
| 19 | }, | ||
| 20 | ); | ||
| 21 | |||
| 22 | method _build__object() { | ||
| 23 | Renard::API::MuPDF::mutool::get_mutool_get_info_object_parsed( $self->filename ); | ||
| 24 | } | ||
| 25 | |||
| 26 | method _get_data( (Str) $key ) { | ||
| 27 | my $obj = $self->_object->resolve_key($key); | ||
| 28 | |||
| 29 | return $obj->data if $obj; | ||
| 30 | } | ||
| 31 | |||
| 32 | has default_properties => ( | ||
| 33 | is => 'ro', | ||
| 34 | isa => ArrayRef, | ||
| 35 | default => sub { | ||
| 36 | [qw( | ||
| 37 | Title | ||
| 38 | Subject | ||
| 39 | Author | ||
| 40 | Keywords | ||
| 41 | Creator | ||
| 42 | Producer | ||
| 43 | CreationDate | ||
| 44 | ModDate | ||
| 45 | )] | ||
| 46 | }, | ||
| 47 | ); | ||
| 48 | |||
| 49 | method Title() :ReturnType(Maybe[Str]) { | ||
| 50 | $self->_get_data('Title'); | ||
| 51 | } | ||
| 52 | |||
| 53 | method Subject() :ReturnType(Maybe[Str]) { | ||
| 54 | $self->_get_data('Subject'); | ||
| 55 | } | ||
| 56 | |||
| 57 | method Author() :ReturnType(Maybe[Str]) { | ||
| 58 | $self->_get_data('Author'); | ||
| 59 | } | ||
| 60 | |||
| 61 | method Keywords() :ReturnType(Maybe[Str]) { | ||
| 62 | $self->_get_data('Keywords'); | ||
| 63 | } | ||
| 64 | |||
| 65 | method Creator() :ReturnType(Maybe[Str]) { | ||
| 66 | $self->_get_data('Creator'); | ||
| 67 | } | ||
| 68 | |||
| 69 | method Producer() :ReturnType(Maybe[Str]) { | ||
| 70 | $self->_get_data('Producer'); | ||
| 71 | } | ||
| 72 | |||
| 73 | method CreationDate() :ReturnType(Maybe[InstanceOf['Renard::API::MuPDF::mutool::DateObject']]) { | ||
| 74 | $self->_get_data('CreationDate'); | ||
| 75 | } | ||
| 76 | |||
| 77 | method ModDate() :ReturnType(Maybe[InstanceOf['Renard::API::MuPDF::mutool::DateObject']]) { | ||
| 78 | $self->_get_data('ModDate'); | ||
| 79 | } | ||
| 80 | |||
| 81 | 1; | ||
| 82 | |||
| 83 | __END__ |