| SVN-Dump documentation | Contained in the SVN-Dump distribution. |
SVN::Dump::Headers - Headers of a SVN dump record
# SVN::Dump::Headers objects are returned by the read_header_block()
# method of SVN::Dump::Reader
A SVN::Dump::Headers object represents the headers of a
SVN dump record.
SVN::Dump::Headers provides the following methods:
Create and return a new empty SVN::Dump::Headers object.
If $hashref is given (it can be a blessed hash reference), the
keys from the hash are used to initialise the headers.
Set the $h header to the value $v.
_ can be used as a replacement for - in the header name.
Get the value of header $h.
_ can be used as a replacement for - in the header name.
Return the list of headers, in canonical order.
Return a string that represents the record headers.
It is possible to guess the record type from its headers.
This method returns a string that represents the record type.
The string is one of revision, node, uuid or format.
The method dies if it can't determine the record type.
When using SVN::Dump to manipulate a SVN dump, one should not directly
access the SVN::Dump::Headers component of a SVN::Dump::Record, but
use the set_header() and get_header() methods of the record object.
SVN::Dump::Record.
Copyright 2006-2011 Philippe 'BooK' Bruhat, All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| SVN-Dump documentation | Contained in the SVN-Dump distribution. |
package SVN::Dump::Headers; use strict; use warnings; use Carp; use Scalar::Util qw( reftype ); my $NL = "\012"; sub new { my ( $class, $headers ) = @_; croak 'First parameter must be a HASH reference' if defined $headers && !( ref $headers && reftype $headers eq 'HASH' ); my $self = bless {}, $class; $self->set( $_ => $headers->{$_} ) for keys %{ $headers || {} }; return $self; } my %headers = ( revision => [ qw( Revision-number Prop-content-length Content-length ) ], node => [ qw( Node-path Node-kind Node-action Node-copyfrom-rev Node-copyfrom-path Prop-delta Prop-content-length Text-copy-source-md5 Text-copy-source-sha1 Text-delta Text-content-length Text-content-md5 Text-content-sha1 Content-length ) ], uuid => ['UUID'], format => ['SVN-fs-dump-format-version'], ); # FIXME Prop-delta and Text-delta in version 3 sub as_string { my ($self) = @_; my $string = ''; for my $k ( @{ $headers{ $self->type() } } ) { $string .= "$k: $self->{$k}$NL" if exists $self->{$k}; } return $string . $NL; } sub type { my ($self) = @_; my $type = exists $self->{'Node-path'} ? 'node' : exists $self->{'Revision-number'} ? 'revision' : exists $self->{'UUID'} ? 'uuid' : exists $self->{'SVN-fs-dump-format-version'} ? 'format' : croak 'Unable to determine the record type'; return $type; } sub set { my ($self, $h, $v) = @_; # FIXME shall we check that the header value is valid? $h =~ tr/_/-/; # allow _ for - simplification return $self->{$h} = $v; } sub get { my ($self, $h) = @_; $h =~ tr/_/-/; # allow _ for - simplification return $self->{$h}; } sub keys { my ($self) = @_; return grep { exists $self->{$_} } @{ $headers{$self->type()} }; } 1; __END__