[Bps-public-commit] r10871 - in SVN-PropDB: lib/SVN/PropDB t

jesse at bestpractical.com jesse at bestpractical.com
Sun Feb 17 23:15:41 EST 2008


Author: jesse
Date: Sun Feb 17 23:15:39 2008
New Revision: 10871

Added:
   SVN-PropDB/lib/SVN/PropDB.pm
   SVN-PropDB/lib/SVN/PropDB/Collection.pm
Modified:
   SVN-PropDB/lib/SVN/PropDB/.Handle.pm.swp
   SVN-PropDB/lib/SVN/PropDB/.Record.pm.swp
   SVN-PropDB/lib/SVN/PropDB/Record.pm
   SVN-PropDB/t/.create.t.swp
   SVN-PropDB/t/create.t

Log:
 * now with working search

Added: SVN-PropDB/lib/SVN/PropDB.pm
==============================================================================
--- (empty file)
+++ SVN-PropDB/lib/SVN/PropDB.pm	Sun Feb 17 23:15:39 2008
@@ -0,0 +1,7 @@
+use warnings;
+use strict;
+
+package SVN::PropDB;
+
+our $VERSION = '0.01';
+1;

Modified: SVN-PropDB/lib/SVN/PropDB/.Handle.pm.swp
==============================================================================
Binary files. No diff available.

Modified: SVN-PropDB/lib/SVN/PropDB/.Record.pm.swp
==============================================================================
Binary files. No diff available.

Added: SVN-PropDB/lib/SVN/PropDB/Collection.pm
==============================================================================
--- (empty file)
+++ SVN-PropDB/lib/SVN/PropDB/Collection.pm	Sun Feb 17 23:15:39 2008
@@ -0,0 +1,54 @@
+use warnings;
+use strict;
+
+package SVN::PropDB::Collection;
+use Params::Validate;
+use base qw/Class::Accessor/;
+__PACKAGE__->mk_accessors(qw'handle');
+use SVN::PropDB::Record;
+
+
+sub new {
+    my $class = shift;
+    my $self = {};
+    bless $self, $class;
+    my %args = validate(@_, { handle => 1});
+    $self->handle($args{'handle'});
+    return $self;
+}
+
+
+sub matching {
+    my $self = shift;
+    my $coderef = shift;
+
+    # find all items,
+    my $nodes = $self->handle->current_root->dir_entries('/_propdb','/');
+    # run coderef against each item;
+    # if it matches, add it to _items
+    foreach my $key (keys %$nodes) {
+        warn "considering $key";    
+        my $record = SVN::PropDB::Record->new(handle => $self->handle);
+        $record->load(uuid => $key);
+        if($coderef->($record)) {
+            push @{$self->{_items}}, $record;
+           } else {
+            warn "no love!";
+        }
+    
+    }
+
+
+    #return a count of items found
+
+
+}
+
+sub as_array_ref {
+    my $self = shift;
+    return $self->{_items}||[];
+
+}
+
+
+1;

Modified: SVN-PropDB/lib/SVN/PropDB/Record.pm
==============================================================================
--- SVN-PropDB/lib/SVN/PropDB/Record.pm	(original)
+++ SVN-PropDB/lib/SVN/PropDB/Record.pm	Sun Feb 17 23:15:39 2008
@@ -30,9 +30,9 @@
 sub load {
     my $self = shift;
     my %args = validate(@_, { uuid => 1});
-    my %props = $self->handle->fetch_node_props( uuid => $args{uuid});
+    #my %props = $self->handle->get_node_props( uuid => $args{uuid});
     $self->uuid($args{uuid});
-    $self->props(\%props);
+    #$self->props(\%props);
 
 }
 
@@ -47,7 +47,7 @@
     return $self->handle->get_node_props(uuid => $self->uuid);
 }
 
-sub get_prop {
+sub prop {
     my $self = shift;
     my %args = validate(@_, {name => 1});
     return $self->get_props->{$args{'name'}};

Modified: SVN-PropDB/t/.create.t.swp
==============================================================================
Binary files. No diff available.

Modified: SVN-PropDB/t/create.t
==============================================================================
--- SVN-PropDB/t/create.t	(original)
+++ SVN-PropDB/t/create.t	Sun Feb 17 23:15:39 2008
@@ -15,9 +15,44 @@
 isa_ok($record, 'SVN::PropDB::Record');
 my $uuid  = $record->create(props => { name => 'Jesse', age => 31});
 ok($uuid);
-is($record->get_prop(name => 'age'), 31);
+is($record->prop(name => 'age'), 31);
 $record->set_prop( name => 'age', value => 32);
-is($record->get_prop(name => 'age'), 32);
+is($record->prop(name => 'age'), 32);
 
+    my $kaia = $record->create(props => { name => 'Kaia', age => 24});
+ok( $kaia);
+my $mao = $record->create(props => { name => 'Mao', age => 0.7, species => 'cat'});
+ok ($mao);
+my $mei= $record->create(props => { name => 'Mei', age => "0.7", species => 'cat'});
+ok ($mei);
+use_ok('SVN::PropDB::Collection');
+
+my $people = SVN::PropDB::Collection->new( handle => $cxn);
+$people->matching(sub { (shift->prop(name => 'species')||'') ne 'cat'});
+is($#{$people->as_array_ref}, 1);
+my @people= @{$people->as_array_ref};
+is_deeply([ sort map {$_->prop(name => 'name')} @people], [qw(Jesse Kaia)]);
+
+my $cats = SVN::PropDB::Collection->new( handle => $cxn);
+$cats->matching(sub { (shift->prop(name => 'species')||'') eq 'cat'});
+is($#{$cats->as_array_ref}, 1);
+my @cats= @{$cats->as_array_ref};
+for (@cats) {
+    is ($_->prop(name=>'age') , "0.7");
+}
+is_deeply([ sort map {$_->prop(name => 'name')} @cats], [qw(Mao Mei)]);
+
+my $cat = SVN::PropDB::Record->new(handle => $cxn);
+$cat->load(uuid => $mao);
+$cat->set_prop(name => 'age', value => '0.8');
+my $cat2 = SVN::PropDB::Record->new(handle => $cxn);
+$cat2->load(uuid => $mei);
+$cat2->set_prop(name => 'age', value => '0.8');
+
+is($#{$cats->as_array_ref}, 1);
+my @cats= @{$cats->as_array_ref};
+for (@cats) {
+    is ($_->prop(name=>'age') , "0.8");
+}
 
 1;



More information about the Bps-public-commit mailing list