SVN::Dump::Property - A property block from a svn dump


SVN-Dump documentation Contained in the SVN-Dump distribution.

Index


Code Index:

NAME

Top

SVN::Dump::Property - A property block from a svn dump

SYNOPSIS

Top

DESCRIPTION

Top

The SVN::Dump::Property class represents a property block in a svn dump.

METHODS

Top

The following methods are available:

new()

Create a new empty property block.

set( $key => $value)

Set the $key property with value $value.

get( $key )

Get the value of property $key.

delete( @keys )

Delete the keys @keys. Behaves like the builtin delete() on a hash.

keys()

Return the property block keys, in the order they were entered.

values()

Return the property block values, in the order they were entered.

as_string()

Return a string representation of the property block.

SEE ALSO

Top

COPYRIGHT & LICENSE

Top


SVN-Dump documentation Contained in the SVN-Dump distribution.

package SVN::Dump::Property;

use strict;
use warnings;

my $NL = "\012";

# FIXME should I use Tie::Hash::IxHash or Tie::Hash::Indexed?
sub new {
    my ( $class, @args ) = @_;
    return bless {
        keys => [],
        hash => {},
    }, $class;
}

sub set {
    my ( $self, $k, $v ) = @_;

    push @{ $self->{keys} }, $k if !exists $self->{hash}->{$k};
    $self->{hash}{$k} = $v;
}
sub get    { return $_[0]{hash}{ $_[1] }; }
sub keys   { return @{ $_[0]{keys} }; }
sub values { return @{ $_[0]{hash} }{ @{ $_[0]{keys} } }; }
sub delete {
    my ( $self, @keys ) = @_;
    return if !@keys;
    my $re = qr/^@{[join '|', map { quotemeta } @keys]}$/;
    $self->{keys} = [ grep { !/$re/ } @{ $self->{keys} } ];
    delete @{ $self->{hash} }{@keys};
}

sub as_string {
    my ($self) = @_;
    my $string = '';

    $string .=
        defined $self->{hash}{$_}
        # existing key
        ? ( "K " . length($_) . $NL ) . "$_$NL"
        . ( "V " . length( $self->{hash}{$_} ) . $NL )
        . "$self->{hash}{$_}$NL"
        # deleted key (v3)
        : ( "D " . length($_) . "$NL$_$NL" )
        for @{ $self->{keys} };

    # end marker
    $string .= "PROPS-END$NL";

    return $string;
}

1;

__END__