| 1 | package DublinCore::Element; | ||||||||||
| 2 | |||||||||||
| 3 | =head1 NAME | ||||||||||
| 4 | |||||||||||
| 5 | DublinCore::Element - Class for representing a Dublin Core element | ||||||||||
| 6 | |||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||
| 8 | |||||||||||
| 9 | my $element = DublinCore::Element->new( \%info ); | ||||||||||
| 10 | print "content: ", $element->content(), "\n"; | ||||||||||
| 11 | print "qualifier: ", $element->qualifier(), "\n"; | ||||||||||
| 12 | print "language: ", $element->language(), "\n"; | ||||||||||
| 13 | print "scheme: ", $element->scheme(), "\n"; | ||||||||||
| 14 | |||||||||||
| 15 | =head1 DESCRIPTION | ||||||||||
| 16 | |||||||||||
| 17 | DublinCore::Record methods such as element(), elements(), title(), etc return | ||||||||||
| 18 | DublinCore::Element objects as their result. These can be queried | ||||||||||
| 19 | further to extract an elements content, qualifier, language, and schema. For a | ||||||||||
| 20 | definition of these attributes please see RFC 2731 and | ||||||||||
| 21 | L<http://www.dublincore.org>. | ||||||||||
| 22 | |||||||||||
| 23 | =cut | ||||||||||
| 24 | |||||||||||
| 25 | 5 | ▶ | use base qw( Class::Accessor ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | |||||||||||
| 27 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | 5 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 29 | |||||||||||
| 30 | 5 | our $VERSION = '0.03'; | |||||||||
| 31 | |||||||||||
| 32 | 5 | __PACKAGE__->mk_accessors( qw( name qualifier content language scheme is_empty ) ); | |||||||||
| 33 | |||||||||||
| 34 | =head1 METHODS | ||||||||||
| 35 | |||||||||||
| 36 | =head2 new() | ||||||||||
| 37 | |||||||||||
| 38 | The constructor. Take a hashref of input arguments. | ||||||||||
| 39 | |||||||||||
| 40 | =cut | ||||||||||
| 41 | |||||||||||
| 42 | 32 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 43 | 32 | my $class = shift; | |||||||||
| 44 | 32 | my $self = $class->SUPER::new( @_ ); | |||||||||
| 45 | |||||||||||
| 46 | 32 | bless $self, $class; | |||||||||
| 47 | |||||||||||
| 48 | 32 | $self->is_empty( 1 ); | |||||||||
| 49 | |||||||||||
| 50 | 32 | return $self; | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | =head2 content() | ||||||||||
| 54 | |||||||||||
| 55 | Gets and sets the content of the element. | ||||||||||
| 56 | |||||||||||
| 57 | ## extract the element | ||||||||||
| 58 | my $title = $record->element( 'title' ); | ||||||||||
| 59 | print $title->content(); | ||||||||||
| 60 | |||||||||||
| 61 | ## or you can chain them together | ||||||||||
| 62 | print $record->element( 'title' )->content(); | ||||||||||
| 63 | |||||||||||
| 64 | =head2 qualifier() | ||||||||||
| 65 | |||||||||||
| 66 | Gets and sets the qualifier used by the element. | ||||||||||
| 67 | |||||||||||
| 68 | =head2 language() | ||||||||||
| 69 | |||||||||||
| 70 | Gets and sets the language of the content in element. | ||||||||||
| 71 | |||||||||||
| 72 | =head2 scheme() | ||||||||||
| 73 | |||||||||||
| 74 | Gets and sets the scheme used by the element. | ||||||||||
| 75 | |||||||||||
| 76 | =head2 name() | ||||||||||
| 77 | |||||||||||
| 78 | Gets and sets the element name (title, creator, date, etc). | ||||||||||
| 79 | |||||||||||
| 80 | =head2 is_empty() | ||||||||||
| 81 | |||||||||||
| 82 | Gets and sets the "empty" status of an element. This is useful when | ||||||||||
| 83 | using DublinCore::Record's element() method. | ||||||||||
| 84 | |||||||||||
| 85 | To see if the record has an creator elements: | ||||||||||
| 86 | |||||||||||
| 87 | if( $record->element( 'creator' )->is_empty ) { | ||||||||||
| 88 | # no creators | ||||||||||
| 89 | } | ||||||||||
| 90 | |||||||||||
| 91 | |||||||||||
| 92 | =head2 set() | ||||||||||
| 93 | |||||||||||
| 94 | This function overrides the default set() behavior in order to remove the | ||||||||||
| 95 | is_empty flag. | ||||||||||
| 96 | |||||||||||
| 97 | =cut | ||||||||||
| 98 | |||||||||||
| 99 | 107 | ▶ | sub set { | ||||||||
|
Subroutine
set: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 100 | 107 | my $self = shift; | |||||||||
| 101 | 107 | ▶ | $self->SUPER::set( 'is_empty' => 0 ) if $self->is_empty; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 102 | 107 | $self->SUPER::set( @_ ); | |||||||||
| 103 | } | ||||||||||
| 104 | |||||||||||
| 105 | =head1 SEE ALSO | ||||||||||
| 106 | |||||||||||
| 107 | =over 4 | ||||||||||
| 108 | |||||||||||
| 109 | =item * DublinCore::Record | ||||||||||
| 110 | |||||||||||
| 111 | =back | ||||||||||
| 112 | |||||||||||
| 113 | =head1 AUTHOR | ||||||||||
| 114 | |||||||||||
| 115 | =over 4 | ||||||||||
| 116 | |||||||||||
| 117 | =item * Ed Summers E<lt>ehs@pobox.comE<gt> | ||||||||||
| 118 | |||||||||||
| 119 | =item * Brian Cassidy E<lt>bricas@cpan.orgE<gt> | ||||||||||
| 120 | |||||||||||
| 121 | =back | ||||||||||
| 122 | |||||||||||
| 123 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 124 | |||||||||||
| 125 | Copyright 2007 by Ed Summers, Brian Cassidy | ||||||||||
| 126 | |||||||||||
| 127 | This library is free software; you can redistribute it and/or modify | ||||||||||
| 128 | it under the same terms as Perl itself. | ||||||||||
| 129 | |||||||||||
| 130 | =cut | ||||||||||
| 131 | |||||||||||
| 132 | 5 | 1; | |||||||||