| 1 | package SVG::DOM2::Element::MetaData; | ||
| 2 | |||
| 3 | 1 | ▶ | use base "XML::DOM2::Element"; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | use strict; | ||
| 5 | |||
| 6 | sub new | ||
| 7 | { | ||
| 8 | my ($proto, %args) = @_; | ||
| 9 | return $proto->SUPER::new('metadata', %args); | ||
| 10 | } | ||
| 11 | |||
| 12 | sub data | ||
| 13 | { | ||
| 14 | my ($self) = @_; | ||
| 15 | warn "Trying to get DATA: $self\n"; | ||
| 16 | if(not $self->{'data'}) { | ||
| 17 | # Generate with RDF: | ||
| 18 | my $result = {}; | ||
| 19 | my ($rdf) = $self->getChildrenByName('rdf:RDF'); | ||
| 20 | if($rdf) { | ||
| 21 | my ($work) = $rdf->getChildrenByName('cc:Work'); | ||
| 22 | $result = $self->_format_rdf_hash($work); | ||
| 23 | $self->{'rdf'} = 1; | ||
| 24 | } | ||
| 25 | $self->{'data'} = $result; | ||
| 26 | } | ||
| 27 | |||
| 28 | return $self->{'data'}; | ||
| 29 | } | ||
| 30 | |||
| 31 | sub _format_rdf | ||
| 32 | { | ||
| 33 | my ($self, $child) = @_; | ||
| 34 | # Resource | ||
| 35 | my $rdfns = $self->document->getNamespace('rdf'); | ||
| 36 | my $resource = $child->getAttributeNS($rdfns, 'resource'); | ||
| 37 | return $resource->value if defined $resource; | ||
| 38 | # Value | ||
| 39 | return $child->cdata->text if $child->hasCDATA; | ||
| 40 | # Structure | ||
| 41 | my $result; | ||
| 42 | my ($achild) = $child->getChildren; | ||
| 43 | return '' if not $achild; | ||
| 44 | if($achild->localName =~ /Bag|Alt|Seq/) { | ||
| 45 | # Array | ||
| 46 | $result = [ map { $self->_format_rdf($_) } $achild->getChildrenByName('rdf:li') ]; | ||
| 47 | } elsif($achild->localName eq 'Agent') { | ||
| 48 | # Hash | ||
| 49 | $result = $self->_format_rdf_hash($achild); | ||
| 50 | } | ||
| 51 | return $result; | ||
| 52 | } | ||
| 53 | |||
| 54 | sub _format_rdf_hash | ||
| 55 | { | ||
| 56 | my ($self, $child) = @_; | ||
| 57 | my $result = {}; | ||
| 58 | foreach my $achild ($child->getChildren) { | ||
| 59 | my $name = $achild->localName; | ||
| 60 | $result->{$name} = $self->_format_rdf($achild); | ||
| 61 | } | ||
| 62 | return $result; | ||
| 63 | } | ||
| 64 | |||
| 65 | sub list | ||
| 66 | { | ||
| 67 | my ($self) = @_; | ||
| 68 | return $self->list_hash($self->data); | ||
| 69 | } | ||
| 70 | |||
| 71 | sub list_data | ||
| 72 | { | ||
| 73 | my ($self, $data) = @_; | ||
| 74 | return '"'.$data.'"' if not ref($data); | ||
| 75 | if(UNIVERSAL::isa($data, 'HASH')) { | ||
| 76 | return $self->list_hash($data); | ||
| 77 | } elsif(UNIVERSAL::isa($data, 'ARRAY')) { | ||
| 78 | return $self->list_array($data); | ||
| 79 | } | ||
| 80 | } | ||
| 81 | |||
| 82 | sub list_array | ||
| 83 | { | ||
| 84 | my ($self, $array) = @_; | ||
| 85 | return '['.join(', ',map { $self->list_data($_) } @{$array}).']'; | ||
| 86 | } | ||
| 87 | |||
| 88 | sub list_hash | ||
| 89 | { | ||
| 90 | my ($self, $hash) = @_; | ||
| 91 | return '{'.join(', ', map { $_.' = '.$self->list_data($hash->{$_}) } keys(%{$hash}) ).'}'; | ||
| 92 | } | ||
| 93 | |||
| 94 | =head2 MetaData Fields | ||
| 95 | |||
| 96 | title - Image title | ||
| 97 | description - Image discription | ||
| 98 | subject - Array of subjects (contexts) | ||
| 99 | publisher - Company who publishes the work | ||
| 100 | creator - Author, Artist, Designer ect. | ||
| 101 | rights - Owner of the work (rights holder) | ||
| 102 | date - Creation date | ||
| 103 | license - Published License | ||
| 104 | language - Language (if applicable) | ||
| 105 | |||
| 106 | =cut | ||
| 107 | sub title { shift->datum('title', @_) } | ||
| 108 | sub description { shift->datum('description', @_) } | ||
| 109 | sub subject { shift->datum('subject', @_) } | ||
| 110 | sub publisher { shift->datum('publisher', @_) } | ||
| 111 | sub creator { shift->datum('creator', @_) } | ||
| 112 | sub rights { shift->datum('rights', @_) } | ||
| 113 | sub date { shift->datum('date', @_) } | ||
| 114 | sub license { shift->datum('license', @_) } | ||
| 115 | sub language { shift->datum('language', @_) } | ||
| 116 | |||
| 117 | sub datum | ||
| 118 | { | ||
| 119 | my ($self, $name, $value) = @_; | ||
| 120 | if(defined($value)) { | ||
| 121 | $self->data->{$name} = $value; | ||
| 122 | } else { | ||
| 123 | $value = $self->data->{$name}; | ||
| 124 | } | ||
| 125 | return $value; | ||
| 126 | } | ||
| 127 | |||
| 128 | return 1; | ||