[Bps-public-commit] r10821 - in SVN-PropDB: lib/SVN lib/SVN/PropDB t
jesse at bestpractical.com
jesse at bestpractical.com
Wed Feb 13 23:19:07 EST 2008
Author: jesse
Date: Wed Feb 13 23:19:06 2008
New Revision: 10821
Added:
SVN-PropDB/lib/
SVN-PropDB/lib/SVN/
SVN-PropDB/lib/SVN/PropDB/
SVN-PropDB/lib/SVN/PropDB/.Handle.pm.swp (contents, props changed)
SVN-PropDB/lib/SVN/PropDB/.Record.pm.swp (contents, props changed)
SVN-PropDB/lib/SVN/PropDB/Editor.pm
SVN-PropDB/lib/SVN/PropDB/Handle.pm
SVN-PropDB/lib/SVN/PropDB/Record.pm
SVN-PropDB/t/
SVN-PropDB/t/.create.t.swp (contents, props changed)
SVN-PropDB/t/basic.t
SVN-PropDB/t/create.t
SVN-PropDB/t/use.t
Log:
These are not the droids you're looking for
Added: SVN-PropDB/lib/SVN/PropDB/.Handle.pm.swp
==============================================================================
Binary file. No diff available.
Added: SVN-PropDB/lib/SVN/PropDB/.Record.pm.swp
==============================================================================
Binary file. No diff available.
Added: SVN-PropDB/lib/SVN/PropDB/Editor.pm
==============================================================================
--- (empty file)
+++ SVN-PropDB/lib/SVN/PropDB/Editor.pm Wed Feb 13 23:19:06 2008
@@ -0,0 +1,11 @@
+use warnings;
+use strict;
+
+package SVN::PropDB::Editor;
+use base qw/SVN::Simple::Edit/;
+
+
+
+
+1;
+
Added: SVN-PropDB/lib/SVN/PropDB/Handle.pm
==============================================================================
--- (empty file)
+++ SVN-PropDB/lib/SVN/PropDB/Handle.pm Wed Feb 13 23:19:06 2008
@@ -0,0 +1,124 @@
+use warnings;
+use strict;
+
+package SVN::PropDB::Handle;
+use base 'Class::Accessor';
+use Params::Validate;
+use Data::Dumper;
+use Data::UUID;
+
+use SVN::PropDB::Editor;
+use SVN::Core;
+use SVN::Repos;
+use SVN::Fs;
+
+__PACKAGE__->mk_accessors(qw(repo_path repo_handle));
+
+sub new {
+ my $class = shift;
+ my $self = {};
+ bless $self, $class;
+ my %args = validate( @_, { repository => 1 } );
+
+ $self->repo_path( $args{'repository'} );
+ $self->_connect();
+
+ return $self;
+}
+
+our $MYROOT = '/_propdb';
+sub current_root {
+ my $self = shift;
+ $self->repo_handle->fs->revision_root ($self->repo_handle->fs->youngest_rev);
+}
+
+
+
+sub _connect {
+ my $self = shift;
+ my $repos = SVN::Repos::open( $self->repo_path );
+ warn "opened the repos";
+ $self->repo_handle($repos);
+ unless($self->current_root->is_dir($MYROOT)) {
+ my $edit = $self->begin_edit;
+ $edit->root->make_dir($MYROOT);
+ $self->commit_edit($edit);
+ }
+
+}
+
+sub begin_edit {
+ my $self = shift;
+ my $fs = $self->repo_handle->fs;
+ my $txn = $fs->begin_txn($fs->youngest_rev);
+
+ return $txn;
+}
+
+sub commit_edit {
+ my $self = shift;
+ my $txn = shift;
+ $txn->commit;
+
+}
+
+sub create_node {
+ my $self = shift;
+ my %args = validate( @_, { uuid => 1, props => 1 } );
+ my $edit = $self->begin_edit();
+ my $file = $self->file_for(uuid => $args{uuid});
+ $edit->root->make_file( $file );
+ {
+ my $stream = $edit->root->apply_text($file, undef);
+ print $stream Dumper($args{'props'});
+ close $stream;
+ }
+ $self->_set_node_props(uuid => $args{uuid}, props => $args{props}, edit => $edit);
+ $self->commit_edit($edit);
+
+}
+
+sub _set_node_props {
+my $self = shift;
+ my %args = validate(@_, { uuid => 1, props=> 1, edit => 1});
+ my $file = $self->file_for(uuid => $args{uuid});
+ foreach my $prop (keys %{$args{'props'}}) {
+ $args{edit}->root->change_node_prop($file,$prop, $args{'props'}->{$prop}, undef);
+ }
+}
+
+sub delete_node {
+ my $self = shift;
+ my %args = validate( @_, { uuid => 1 } );
+
+}
+
+sub set_node_props {
+ my $self = shift;
+ my %args = validate( @_, { uuid => 1, props => 1 } );
+ my $edit = $self->begin_edit();
+ my $file = $self->file_for(uuid => $args{uuid});
+ $self->_set_node_props(uuid => $args{uuid}, props => $args{props} ,edit => $edit);
+ $self->commit_edit($edit);
+
+}
+
+
+
+sub get_node_props {
+ my $self = shift;
+ my %args = validate( @_, { uuid => 1, } );
+ return $self->current_root->node_proplist($self->file_for(uuid => $args{'uuid'}));
+}
+
+
+
+sub file_for {
+my $self = shift;
+ my %args = validate( @_, { uuid => 1, } );
+ my $file = $MYROOT."/".$args{'uuid'};
+ return $file;
+
+}
+
+1;
Added: SVN-PropDB/lib/SVN/PropDB/Record.pm
==============================================================================
--- (empty file)
+++ SVN-PropDB/lib/SVN/PropDB/Record.pm Wed Feb 13 23:19:06 2008
@@ -0,0 +1,62 @@
+
+use warnings;
+use strict;
+package SVN::PropDB::Record;
+use Params::Validate;
+use base qw'Class::Accessor';
+__PACKAGE__->mk_accessors(qw'handle props uuid');
+my $UUIDGEN = Data::UUID->new();
+
+sub new {
+ my $class = shift;
+ my $self = {};
+ bless $self, $class;
+ my %args = validate(@_, { handle => 1});
+ $self->handle($args{'handle'});
+ return $self;
+}
+
+sub create {
+ my $self = shift;
+ my %args = validate(@_, { props => 1});
+
+ $self->uuid($UUIDGEN->create_str);
+ $self->handle->create_node( props => $args{'props'}, uuid => $self->uuid);
+
+ return $self->uuid;
+}
+
+
+sub load {
+ my $self = shift;
+ my %args = validate(@_, { uuid => 1});
+ my %props = $self->handle->fetch_node_props( uuid => $args{uuid});
+ $self->uuid($args{uuid});
+ $self->props(\%props);
+
+}
+
+sub set_prop {
+ my $self = shift;
+ my %args = validate(@_, { name => 1, value => 1});
+ $self->handle->set_node_props(uuid => $self->uuid, props =>{$args{name}=> $args{value}});
+}
+
+sub get_props {
+ my $self = shift;
+ return $self->handle->get_node_props(uuid => $self->uuid);
+}
+
+sub get_prop {
+ my $self = shift;
+ my %args = validate(@_, {name => 1});
+ return %{$self->get_props}->{$args{'name'}};
+}
+
+
+sub delete_prop {
+ my $self = shift;
+ my %args = validate(@_, { name => 1});
+ $self->handle->delete_node_prop(uuid => $self->uuid, name => $args{'name'});
+}
+1;
Added: SVN-PropDB/t/.create.t.swp
==============================================================================
Binary file. No diff available.
Added: SVN-PropDB/t/basic.t
==============================================================================
--- (empty file)
+++ SVN-PropDB/t/basic.t Wed Feb 13 23:19:06 2008
@@ -0,0 +1,25 @@
+use SVN::Simple::Edit;
+ require SVN::Core;
+ require SVN::Repos;
+ require SVN::Fs;
+use Data::Dumper;
+ $repospath = "/tmp/repo-".$$;
+ `svnadmin create $repospath`;
+
+ $repos = SVN::Repos::open($repospath);
+$fs = $repos->fs;
+
+ $edit = SVN::Simple::Edit->new(_editor => [SVN::Repos::get_commit_editor($repos, "file://$repospath",
+ '/', 'root', 'FOO', \&committed)],
+ );
+ $checksum = '1234';
+ $edit->open_root($fs->youngest_rev);
+ $edit->add_directory ('trunk');
+ $edit->add_file ('trunk/filea');
+ $edit->modify_file ("trunk/filea", "content", $checksum);
+ $edit->close_edit ();
+
+
+ sub committed {
+ warn Dumper(\@_);
+ }
Added: SVN-PropDB/t/create.t
==============================================================================
--- (empty file)
+++ SVN-PropDB/t/create.t Wed Feb 13 23:19:06 2008
@@ -0,0 +1,23 @@
+use warnings;
+use strict;
+use Test::More 'no_plan';
+use File::Temp qw'tempdir';
+
+use_ok('SVN::PropDB::Handle');
+my $REPO= tempdir(CLEANUP => 0).'/repo-'.$$;
+ok(! -d $REPO);
+`svnadmin create $REPO`;
+ok(-d $REPO, "The repo exists ater svnadmin create");
+my $cxn = SVN::PropDB::Handle->new( repository => "$REPO");
+isa_ok($cxn, 'SVN::PropDB::Handle', "Got the cxn");
+use_ok('SVN::PropDB::Record');
+my $record = SVN::PropDB::Record->new(handle =>$cxn);
+isa_ok($record, 'SVN::PropDB::Record');
+my $uuid = $record->create(props => { name => 'Jesse', age => 31});
+ok($uuid);
+is($record->get_prop(name => 'age'), 31);
+$record->set_prop( name => 'age', value => 32);
+is($record->get_prop(name => 'age'), 32);
+
+
+1;
Added: SVN-PropDB/t/use.t
==============================================================================
--- (empty file)
+++ SVN-PropDB/t/use.t Wed Feb 13 23:19:06 2008
@@ -0,0 +1,10 @@
+use warnings;
+use strict;
+use Test::More 'no_plan';
+
+
+use_ok('SVN::PropDB::Editor');
+use_ok('SVN::PropDB::Handle');
+use_ok('SVN::PropDB::Record');
+
+1;
More information about the Bps-public-commit
mailing list