From: Luke Saunders Date: Tue, 18 May 2010 15:50:51 +0000 (+0100) Subject: removing largely unnecessary dep on MooseX::Method::Signatures X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=79b18b813ee2d241a78e08a9d68eea0745aada67;p=dbsrgits%2FDBIx-Class-ResultSet-WithMetaData.git removing largely unnecessary dep on MooseX::Method::Signatures --- diff --git a/Makefile.PL b/Makefile.PL index 79e6a95..fefef8e 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -5,7 +5,7 @@ perl_version '5.006001'; all_from 'lib/DBIx/Class/ResultSet/WithMetaData.pm'; requires 'DBIx::Class' => 0.08100; -requires 'MooseX::Method::Signatures' => 0.16; +requires 'Method::Signatures::Simple' => 0.05; requires 'Data::Alias'; requires 'DBIx::Class::ResultClass::HashRefInflator'; diff --git a/lib/DBIx/Class/ResultSet/WithMetaData.pm b/lib/DBIx/Class/ResultSet/WithMetaData.pm index d3cf119..1cf546b 100644 --- a/lib/DBIx/Class/ResultSet/WithMetaData.pm +++ b/lib/DBIx/Class/ResultSet/WithMetaData.pm @@ -5,7 +5,7 @@ use warnings; use Data::Alias; use Moose; -use MooseX::Method::Signatures; +use Method::Signatures::Simple; extends 'DBIx::Class::ResultSet'; has '_row_info' => ( @@ -152,7 +152,8 @@ with that row when the ResultSet is flattened to a datastructure with L_mk_id(row => { $row->get_columns }); } @@ -167,7 +168,8 @@ method add_row_info (Int :$id, :$row, HashRef :$info) { $self->_row_info->{$id} = $info; } -method row_info_for (Int :$id) { +method row_info_for (%opts) { + my $id = $opts{id}; return $self->_row_info->{$id}; } @@ -187,7 +189,8 @@ Convenience method. Essentually a shortcut for $rs->search({}, { order_by => $co =cut -method order_by (Str :$col) { +method order_by (%opts) { + my $col = $opts{col}; $col = "me.$col" unless ($col =~ m/\./); return $self->search({}, { order_by => $col }); } @@ -208,11 +211,13 @@ Convenience method. Essentually a shortcut for $rs->search({}, { rows => $count =cut -method limit (Int :$count) { +method limit (%opts) { + my $count = $opts{count}; return $self->search({}, { rows => $count }); } -method _mk_id (HashRef :$row) { +method _mk_id (%opts) { + my $row = $opts{row}; return join('-', map { $row->{$_} } @{$self->id_cols}); } diff --git a/t/custom_methods.t b/t/custom_methods.t index 9ed2ad9..d32448e 100644 --- a/t/custom_methods.t +++ b/t/custom_methods.t @@ -47,5 +47,27 @@ ok(my $schema = DBICTest->init_schema(), 'got schema'); ], 'display with substring okay'); } +{ + my $artists = $schema->resultset('Artist')->order_by(col => 'artistid')->with_substr->search({}, { prefetch => 'cds', rows => 1 })->display(); + use Data::Dumper; print Dumper($artists); exit; + is_deeply($artists, [ + { + 'artistid' => '1', + 'name' => 'Caterwauler McCrae', + 'substr' => 'Cat' + }, + { + 'artistid' => '2', + 'name' => 'Random Boy Band', + 'substr' => 'Ran' + }, + { + 'artistid' => '3', + 'name' => 'We Are Goth', + 'substr' => 'We ' + } + ], 'display with substring okay'); +} + diff --git a/t/lib/DBICTest/Schema/ResultSet/Artist.pm b/t/lib/DBICTest/Schema/ResultSet/Artist.pm index 0b96f93..b9d6a61 100644 --- a/t/lib/DBICTest/Schema/ResultSet/Artist.pm +++ b/t/lib/DBICTest/Schema/ResultSet/Artist.pm @@ -1,7 +1,7 @@ package DBICTest::Schema::ResultSet::Artist; use Moose; -use MooseX::Method::Signatures; +use Method::Signatures::Simple; extends 'DBICTest::Schema::ResultSet'; method with_substr () { diff --git a/t/var/DBIxClass.db b/t/var/DBIxClass.db index 673dd37..aed523c 100644 Binary files a/t/var/DBIxClass.db and b/t/var/DBIxClass.db differ