1package SVN::Dump::Property; 2$SVN::Dump::Property::VERSION = '0.08'; 3use strict; 4use warnings; 5 6my $NL = "\012"; 7 8# FIXME should I use Tie::Hash::IxHash or Tie::Hash::Indexed? 9sub new { 10 my ( $class, @args ) = @_; 11 return bless { 12 keys => [], 13 hash => {}, 14 }, $class; 15} 16 17sub set { 18 my ( $self, $k, $v ) = @_; 19 20 push @{ $self->{keys} }, $k if !exists $self->{hash}->{$k}; 21 $self->{hash}{$k} = $v; 22} 23sub get { return $_[0]{hash}{ $_[1] }; } 24sub keys { return @{ $_[0]{keys} }; } 25sub values { return @{ $_[0]{hash} }{ @{ $_[0]{keys} } }; } 26sub delete { 27 my ( $self, @keys ) = @_; 28 return if !@keys; 29 my $re = qr/^@{[join '|', map { quotemeta } @keys]}$/; 30 $self->{keys} = [ grep { !/$re/ } @{ $self->{keys} } ]; 31 delete @{ $self->{hash} }{@keys}; 32} 33 34sub as_string { 35 my ($self) = @_; 36 my $string = ''; 37 38 $string .= 39 defined $self->{hash}{$_} 40 # existing key 41 ? ( "K " . length($_) . $NL ) . "$_$NL" 42 . ( "V " . length( $self->{hash}{$_} ) . $NL ) 43 . "$self->{hash}{$_}$NL" 44 # deleted key (v3) 45 : ( "D " . length($_) . "$NL$_$NL" ) 46 for @{ $self->{keys} }; 47 48 # end marker 49 $string .= "PROPS-END$NL"; 50 51 return $string; 52} 53 541; 55 56__END__ 57 58=head1 NAME 59 60SVN::Dump::Property - A property block from a svn dump 61 62=head1 VERSION 63 64version 0.08 65 66=head1 SYNOPSIS 67 68=head1 DESCRIPTION 69 70The SVN::Dump::Property class represents a property block in a svn 71dump. 72 73=head1 METHODS 74 75The following methods are available: 76 77=over 4 78 79=item new() 80 81Create a new empty property block. 82 83=item set( $key => $value) 84 85Set the C<$key> property with value C<$value>. 86 87=item get( $key ) 88 89Get the value of property C<$key>. 90 91=item delete( @keys ) 92 93Delete the keys C<@keys>. Behaves like the builtin C<delete()> on a hash. 94 95=item keys() 96 97Return the property block keys, in the order they were entered. 98 99=item values() 100 101Return the property block values, in the order they were entered. 102 103=item as_string() 104 105Return a string representation of the property block. 106 107=back 108 109=head1 SEE ALSO 110 111L<SVN::Dump>, L<SVN::Dump::Record>. 112 113=head1 COPYRIGHT 114 115Copyright 2006-2013 Philippe Bruhat (BooK), All Rights Reserved. 116 117=head1 LICENSE 118 119This program is free software; you can redistribute it and/or modify it 120under the same terms as Perl itself. 121 122=cut 123