… | |
… | |
21 | no warnings; |
21 | no warnings; |
22 | |
22 | |
23 | use overload |
23 | use overload |
24 | '""' => sub { $_[0]->as_string }; |
24 | '""' => sub { $_[0]->as_string }; |
25 | |
25 | |
26 | =item $metadata = new Net::FCP::Metadata $string_or_object |
26 | =item $metadata = new Net::FCP::Metadata [$string_or_object] |
27 | |
27 | |
28 | Creates a new metadata Object from the given string or reference. The |
28 | Creates a new metadata Object from the given string or reference. The |
29 | object is overloaded and will stringify into the corresponding string form |
29 | object is overloaded and will stringify into the corresponding string form |
30 | (which might be slightly different than the string it was created from). |
30 | (which might be slightly different than the string it was created from). |
31 | |
31 | |
|
|
32 | If no arguments is given, creates a new metadata object with just a |
|
|
33 | C<version> part. |
|
|
34 | |
32 | The object is implemented as a hash reference. See C<parse_metadata>, |
35 | The object is implemented as a hash reference. See C<parse_metadata>, |
33 | below, for info on it's structure. |
36 | below, for info on it's structure. |
34 | |
37 | |
35 | =cut |
38 | =cut |
36 | |
39 | |
37 | sub new { |
40 | sub new { |
38 | my ($class, $data) = @_; |
41 | my ($class, $data) = @_; |
39 | |
42 | |
40 | $data = ref $data ? %$data : parse_metadata ($data); |
43 | $data = ref $data ? %$data |
|
|
44 | : $data ? parse_metadata ($data) |
|
|
45 | : { version => { revision => 1 } }; |
41 | |
46 | |
42 | bless $data, $class; |
47 | bless $data, $class; |
43 | } |
48 | } |
44 | |
49 | |
45 | =item $metadata->as_string |
50 | =item $metadata->as_string |
46 | |
51 | |
47 | Returns the string form of the metadata data. |
52 | Returns the string form of the metadata data. |
48 | |
|
|
49 | |
53 | |
50 | =cut |
54 | =cut |
51 | |
55 | |
52 | sub as_string { |
56 | sub as_string { |
53 | build_metadata ($_[0]); |
57 | build_metadata ($_[0]); |
|
|
58 | } |
|
|
59 | |
|
|
60 | =item $metadata->add_redirect ($name, $target[ info1 => arg1...]) |
|
|
61 | |
|
|
62 | Add a simple redirection to the C<document> section to the given |
|
|
63 | target. All extra arguments will be added to the C<info> subsection and |
|
|
64 | often contains C<description> and C<format> fields. |
|
|
65 | |
|
|
66 | =cut |
|
|
67 | |
|
|
68 | sub add_redirect { |
|
|
69 | my ($self, $name, $target, %info) = @_; |
|
|
70 | |
|
|
71 | push @{ $self->{document} }, { |
|
|
72 | redirect => { target => $target }, |
|
|
73 | $name ? (name => $name) : (), |
|
|
74 | %info ? (info => \%info) : (), |
|
|
75 | }; |
54 | } |
76 | } |
55 | |
77 | |
56 | =item $meta = Net::FCP::Metadata::parse_metadata $string |
78 | =item $meta = Net::FCP::Metadata::parse_metadata $string |
57 | |
79 | |
58 | Internal utility function, do not use directly! |
80 | Internal utility function, do not use directly! |
… | |
… | |
170 | |
192 | |
171 | my $res = |
193 | my $res = |
172 | (build_metadata_hash version => delete $meta->{version}) |
194 | (build_metadata_hash version => delete $meta->{version}) |
173 | . (join "", map +(build_metadata_hash $_, $meta->{$_}), keys %$meta); |
195 | . (join "", map +(build_metadata_hash $_, $meta->{$_}), keys %$meta); |
174 | |
196 | |
175 | substr $res, 0, -5; # get rid of "Part". Broken Syntax.... |
197 | substr $res, -5, 4, ""; # get rid of "Part". Broken Syntax.... |
176 | } |
|
|
177 | |
198 | |
|
|
199 | $res; |
|
|
200 | } |
178 | |
201 | |
179 | =back |
202 | =back |
180 | |
203 | |
181 | =head1 SEE ALSO |
204 | =head1 SEE ALSO |
182 | |
205 | |