ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Net-FCP/FCP/Metadata.pm
(Generate patch)

Comparing Net-FCP/FCP/Metadata.pm (file contents):
Revision 1.2 by root, Fri May 14 16:28:20 2004 UTC vs.
Revision 1.3 by root, Fri May 14 17:47:34 2004 UTC

21no warnings; 21no warnings;
22 22
23use overload 23use 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
28Creates a new metadata Object from the given string or reference. The 28Creates a new metadata Object from the given string or reference. The
29object is overloaded and will stringify into the corresponding string form 29object 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
32If no arguments is given, creates a new metadata object with just a
33C<version> part.
34
32The object is implemented as a hash reference. See C<parse_metadata>, 35The object is implemented as a hash reference. See C<parse_metadata>,
33below, for info on it's structure. 36below, for info on it's structure.
34 37
35=cut 38=cut
36 39
37sub new { 40sub 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
47Returns the string form of the metadata data. 52Returns the string form of the metadata data.
48
49 53
50=cut 54=cut
51 55
52sub as_string { 56sub as_string {
53 build_metadata ($_[0]); 57 build_metadata ($_[0]);
58}
59
60=item $metadata->add_redirect ($name, $target[ info1 => arg1...])
61
62Add a simple redirection to the C<document> section to the given
63target. All extra arguments will be added to the C<info> subsection and
64often contains C<description> and C<format> fields.
65
66=cut
67
68sub 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
58Internal utility function, do not use directly! 80Internal 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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines