basically works
luke [Mon, 25 May 2009 23:36:21 +0000 (23:36 +0000)]
Makefile.PL
lib/DBIx/Class/ResultSet/WithMetaData.pm
t/basic.t
t/lib/DBICTest/Schema/ResultSet.pm [new file with mode: 0644]
t/lib/DBICTest/Schema/ResultSet/Artist.pm [new file with mode: 0644]
t/lib/DBICTest/Schema/ResultSet/CD.pm [new file with mode: 0644]
t/lib/DBICTest/Schema/ResultSet/Producer.pm [new file with mode: 0644]
t/lib/DBICTest/Schema/ResultSet/Tag.pm [new file with mode: 0644]
t/lib/DBICTest/Schema/ResultSet/Track.pm [new file with mode: 0644]

index 3be7d9c..b5dca3e 100644 (file)
@@ -5,7 +5,9 @@ perl_version '5.006001';
 all_from 'lib/DBIx/Class/ResultSet/WithMetaData.pm';
 
 requires 'DBIx::Class' => 0.08;
-requires 'MooseX::Method::Signatures' => 0.13;
+requires 'MooseX::Method::Signatures' => 0.16;
+requires 'Data::Alias';
+requires 'DBIx::Class::ResultClass::HashRefInflator;
 
 build_requires 'Test::More'       => 0.7;
 
index 8179aaf..ede534d 100644 (file)
@@ -18,24 +18,29 @@ has 'was_row' => (
        isa => 'Int'
 );
 
+has 'id_cols' => (
+       is => 'rw',
+       isa => 'ArrayRef',
+);
+       
+
 sub new {
        my $self = shift;
-  my $new = $self->next::method(@_);
-       foreach my $key (qw/_row_info/) {
+
+       my $new = $self->next::method(@_);
+       foreach my $key (qw/_row_info was_row id_cols/) {
                alias $new->{$key} = $new->{attrs}{$key};
-               $new->{$key} = {} unless $new->{$key};
        }
 
-       return $new;
-}
+       unless ($new->_row_info) {
+               $new->_row_info({});
+       }
 
-method with_token {
-       foreach my $row ($self->all) {
-               my $token = $self->tokenify($row->get_column($self->token_col));
-               $self->add_row_info(id => $row->id, info => { join('_', 'token', $self->token_col) => $token });
+       unless ($new->id_cols && scalar(@{$new->id_cols})) {
+               $new->id_cols([sort $new->result_source->primary_columns]);
        }
 
-       return $self;
+       return $new;
 }
 
 method display () {
@@ -43,7 +48,7 @@ method display () {
   $rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
   my @rows;
        foreach my $row ($rs->all) {
-               if (my $info = $self->row_info_for(id => $row->{id})) {
+               if (my $info = $self->row_info_for(id => $self->_mk_id(row => $row))) {
                        $row = { %{$row}, %{$info} };
                }
                push(@rows, $row);
@@ -78,6 +83,20 @@ method limit (Int :$count) {
        return $self->search({}, { rows => $count });
 }
 
+method with_token {
+       foreach my $row ($self->all) {
+               my $token = $self->tokenify($row->get_column($self->token_col));
+               $self->add_row_info(id => $row->id, info => { join('_', 'token', $self->token_col) => $token });
+       }
+
+       return $self;
+}
+
+method _mk_id (HashRef :$row) {
+       return join('-', map { $row->{$_} } @{$self->id_cols});
+}
+       
+
 sub tokenify {
   my ($self, $string) = @_;
 
index 8abbee4..816c7a1 100644 (file)
--- a/t/basic.t
+++ b/t/basic.t
@@ -8,3 +8,5 @@ use Data::Dumper;
 # set up and populate schema
 ok(my $schema = DBICTest->init_schema(), 'got schema');
 
+my $producer_rs = $schema->resultset('Producer')->display();
+warn Dumper($producer_rs);
diff --git a/t/lib/DBICTest/Schema/ResultSet.pm b/t/lib/DBICTest/Schema/ResultSet.pm
new file mode 100644 (file)
index 0000000..6d73ba4
--- /dev/null
@@ -0,0 +1,6 @@
+package DBICTest::Schema::ResultSet;
+
+use Moose;
+extends 'DBIx::Class::ResultSet::WithMetaData';
+
+1;
diff --git a/t/lib/DBICTest/Schema/ResultSet/Artist.pm b/t/lib/DBICTest/Schema/ResultSet/Artist.pm
new file mode 100644 (file)
index 0000000..e78b331
--- /dev/null
@@ -0,0 +1,6 @@
+package DBICTest::Schema::ResultSet::Artist;
+
+use Moose;
+extends 'DBICTest::Schema::ResultSet';
+
+1;
diff --git a/t/lib/DBICTest/Schema/ResultSet/CD.pm b/t/lib/DBICTest/Schema/ResultSet/CD.pm
new file mode 100644 (file)
index 0000000..63863a7
--- /dev/null
@@ -0,0 +1,6 @@
+package DBICTest::Schema::ResultSet::CD;
+
+use Moose;
+extends 'DBICTest::Schema::ResultSet';
+
+1;
diff --git a/t/lib/DBICTest/Schema/ResultSet/Producer.pm b/t/lib/DBICTest/Schema/ResultSet/Producer.pm
new file mode 100644 (file)
index 0000000..9835d91
--- /dev/null
@@ -0,0 +1,6 @@
+package DBICTest::Schema::ResultSet::Producer;
+
+use Moose;
+extends 'DBICTest::Schema::ResultSet';
+
+1;
diff --git a/t/lib/DBICTest/Schema/ResultSet/Tag.pm b/t/lib/DBICTest/Schema/ResultSet/Tag.pm
new file mode 100644 (file)
index 0000000..9d72a7e
--- /dev/null
@@ -0,0 +1,6 @@
+package DBICTest::Schema::ResultSet::Tag;
+
+use Moose;
+extends 'DBICTest::Schema::ResultSet';
+
+1;
diff --git a/t/lib/DBICTest/Schema/ResultSet/Track.pm b/t/lib/DBICTest/Schema/ResultSet/Track.pm
new file mode 100644 (file)
index 0000000..d8aed20
--- /dev/null
@@ -0,0 +1,6 @@
+package DBICTest::Schema::ResultSet::Track;
+
+use Moose;
+extends 'DBICTest::Schema::ResultSet';
+
+1;