[Catalyst-commits] r14360 - in
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX: . CRUD
CRUD/Iterator CRUD/Model CRUD/ModelAdapter CRUD/Object CRUD/Test
karpet at dev.catalyst.perl.org
karpet at dev.catalyst.perl.org
Wed Oct 31 03:58:29 GMT 2012
Author: karpet
Date: 2012-10-31 03:58:29 +0000 (Wed, 31 Oct 2012)
New Revision: 14360
Modified:
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Controller.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Iterator.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Iterator/File.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model/File.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model/Utils.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/ModelAdapter/File.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Object.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Object/File.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/REST.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Results.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Test/Controller.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Test/Form.pm
Log:
experimental list_related and view_related chained methods
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Controller.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Controller.pm 2012-10-31 03:57:11 UTC (rev 14359)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Controller.pm 2012-10-31 03:58:29 UTC (rev 14360)
@@ -37,7 +37,7 @@
naked_results => 0,
);
-our $VERSION = '0.52';
+our $VERSION = '0.52_01';
=head1 NAME
@@ -51,18 +51,18 @@
use base qw( CatalystX::CRUD::Controller );
__PACKAGE__->config(
- form_class => 'MyForm::Foo',
- init_form => 'init_with_foo',
- init_object => 'foo_from_form',
- default_template => 'path/to/foo/edit.tt',
- model_name => 'Foo',
- model_adapter => 'FooAdapter', # optional
- model_meta => { moniker => 'SomeTable' }, # optional
- primary_key => 'id',
- view_on_single_result => 0,
- page_size => 50,
- allow_GET_writes => 0,
- naked_results => 0,
+ form_class => 'MyForm::Foo',
+ init_form => 'init_with_foo',
+ init_object => 'foo_from_form',
+ default_template => 'path/to/foo/edit.tt',
+ model_name => 'Foo',
+ model_adapter => 'FooAdapter', # optional
+ model_meta => { moniker => 'SomeTable' }, # optional
+ primary_key => 'id',
+ view_on_single_result => 0,
+ page_size => 50,
+ allow_GET_writes => 0,
+ naked_results => 0,
);
1;
@@ -73,6 +73,8 @@
# foo/<pk>/view
# foo/<pk>/save
# foo/<pk>/rm
+ # foo/<pk>/<relname>/<pk2>/add
+ # foo/<pk>/<relname>/<pk2>/rm
# foo/create
# foo/list
# foo/search
@@ -650,6 +652,50 @@
$c->res->status(204); # enacted, no content
}
+=head2 list_related
+
+Attribute: chained to related().
+
+Returns list of related objects.
+
+Example:
+
+ http://yoururl/user/123/group/list
+
+will return groups related to user C<123>.
+
+=cut
+
+sub list_related : PathPart('list') Chained('fetch') CaptureArgs(1) {
+ my ( $self, $c, $rel ) = @_;
+ return if $self->has_errors($c);
+ $self->do_model( $c, 'search_related', $c->stash->{object}, $rel, );
+}
+
+=head2 view_related
+
+Attribute: chained to related().
+
+Returns list of related objects.
+
+Example:
+
+ http://yoururl/user/123/group/456/view
+
+will return groups related to user C<123>.
+
+=cut
+
+sub view_related : PathPart('view') Chained('related') Args(0) {
+ my ( $self, $c ) = @_;
+ return if $self->has_errors($c);
+ $self->do_model(
+ $c, 'find_related', $c->stash->{object},
+ $c->stash->{rel_name},
+ $c->stash->{foreign_pk_value}
+ );
+}
+
=head1 INTERNAL METHODS
The following methods are not visible via the URI namespace but
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Iterator/File.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Iterator/File.pm 2012-10-31 03:57:11 UTC (rev 14359)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Iterator/File.pm 2012-10-31 03:58:29 UTC (rev 14360)
@@ -3,7 +3,7 @@
use warnings;
use Carp;
-our $VERSION = '0.52';
+our $VERSION = '0.52_01';
=head1 NAME
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Iterator.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Iterator.pm 2012-10-31 03:57:11 UTC (rev 14359)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Iterator.pm 2012-10-31 03:58:29 UTC (rev 14360)
@@ -4,7 +4,7 @@
use Carp;
use base qw( CatalystX::CRUD );
-our $VERSION = '0.52';
+our $VERSION = '0.52_01';
=head1 NAME
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model/File.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model/File.pm 2012-10-31 03:57:11 UTC (rev 14359)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model/File.pm 2012-10-31 03:58:29 UTC (rev 14360)
@@ -10,7 +10,7 @@
__PACKAGE__->mk_accessors(qw( inc_path ));
-our $VERSION = '0.52';
+our $VERSION = '0.52_01';
# test whether symlink() works at compile time
my $SYMLINK_SUPPORTED = eval { symlink( "", "" ); 1 };
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model/Utils.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model/Utils.pm 2012-10-31 03:57:11 UTC (rev 14359)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model/Utils.pm 2012-10-31 03:58:29 UTC (rev 14360)
@@ -9,7 +9,7 @@
__PACKAGE__->mk_accessors(qw( use_ilike ne_sign ));
-our $VERSION = '0.52';
+our $VERSION = '0.52_01';
=head1 NAME
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model.pm 2012-10-31 03:57:11 UTC (rev 14359)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model.pm 2012-10-31 03:58:29 UTC (rev 14360)
@@ -9,7 +9,7 @@
Catalyst::Model
);
-our $VERSION = '0.52';
+our $VERSION = '0.52_01';
__PACKAGE__->mk_accessors(qw( object_class page_size ));
@@ -275,6 +275,7 @@
sub add_related { shift->throw_error("must implement add_related()") }
sub rm_related { shift->throw_error("must implement rm_related()") }
*remove_related = \&rm_related;
+sub find_related { shift->throw_error("must implement view_related()") }
sub has_relationship {
shift->throw_error("must implement has_relationship()");
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/ModelAdapter/File.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/ModelAdapter/File.pm 2012-10-31 03:57:11 UTC (rev 14359)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/ModelAdapter/File.pm 2012-10-31 03:58:29 UTC (rev 14360)
@@ -3,7 +3,7 @@
use warnings;
use base qw( CatalystX::CRUD::ModelAdapter );
-our $VERSION = '0.52';
+our $VERSION = '0.52_01';
=head1 NAME
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Object/File.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Object/File.pm 2012-10-31 03:57:11 UTC (rev 14359)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Object/File.pm 2012-10-31 03:58:29 UTC (rev 14360)
@@ -13,7 +13,7 @@
__PACKAGE__->mk_accessors(qw( content file ));
__PACKAGE__->delegate_class('Path::Class::File');
-our $VERSION = '0.52';
+our $VERSION = '0.52_01';
=head1 NAME
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Object.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Object.pm 2012-10-31 03:57:11 UTC (rev 14359)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Object.pm 2012-10-31 03:58:29 UTC (rev 14360)
@@ -12,7 +12,7 @@
__PACKAGE__->mk_ro_accessors(qw( delegate ));
__PACKAGE__->mk_classdata('delegate_class');
-our $VERSION = '0.52';
+our $VERSION = '0.52_01';
=head1 NAME
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/REST.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/REST.pm 2012-10-31 03:57:11 UTC (rev 14359)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/REST.pm 2012-10-31 03:58:29 UTC (rev 14360)
@@ -10,7 +10,7 @@
__PACKAGE__->mk_accessors(qw( enable_rpc_compat ));
__PACKAGE__->config( enable_rpc_compat => 0 );
-our $VERSION = '0.52';
+our $VERSION = '0.52_01';
#warn "REST VERSION = $VERSION";
@@ -27,16 +27,16 @@
use MyForm::Foo;
__PACKAGE__->config(
- form_class => 'MyForm::Foo',
- init_form => 'init_with_foo',
- init_object => 'foo_from_form',
- default_template => 'path/to/foo/edit.tt',
- model_name => 'Foo',
- primary_key => 'id',
- view_on_single_result => 0,
- page_size => 50,
- enable_rpc_compat => 0,
- );
+ form_class => 'MyForm::Foo',
+ init_form => 'init_with_foo',
+ init_object => 'foo_from_form',
+ default_template => 'path/to/foo/edit.tt',
+ model_name => 'Foo',
+ primary_key => 'id',
+ view_on_single_result => 0,
+ page_size => 50,
+ enable_rpc_compat => 0,
+ );
1;
@@ -138,7 +138,8 @@
my %rpc_methods
= map { $_ => 1 } qw( create read update delete edit save rm view );
-my %related_methods = map { $_ => 1 } qw( add remove );
+my %related_methods
+ = map { $_ => 1 } qw( add remove list_related view_related );
sub rest : Path {
my ( $self, $c, @arg ) = @_;
@@ -195,6 +196,8 @@
my ( $oid, $rel_name, $fval, $rpc ) = @arg;
$c->log->debug("rest_related OID: $oid") if $c->debug;
+ $c->log->debug("rest_related rel_name=$rel_name fval=$fval rpc=$rpc")
+ if $c->debug;
if ($rpc) {
if ( !$self->enable_rpc_compat or !exists $related_methods{$rpc} ) {
@@ -217,6 +220,9 @@
elsif ( $http_method eq 'DELETE' ) {
$rpc_method = 'remove';
}
+ elsif ( $http_method eq 'GET' ) {
+ $rpc_method = defined $fval ? 'view_related' : 'list_related';
+ }
else {
# related() will screen for GET based on config
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Results.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Results.pm 2012-10-31 03:57:11 UTC (rev 14359)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Results.pm 2012-10-31 03:58:29 UTC (rev 14360)
@@ -8,7 +8,7 @@
__PACKAGE__->mk_ro_accessors(qw( count pager query results ));
-our $VERSION = '0.52';
+our $VERSION = '0.52_01';
=head1 NAME
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Test/Controller.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Test/Controller.pm 2012-10-31 03:57:11 UTC (rev 14359)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Test/Controller.pm 2012-10-31 03:58:29 UTC (rev 14360)
@@ -8,7 +8,7 @@
__PACKAGE__->mk_accessors( qw( form_fields ) );
-our $VERSION = '0.52';
+our $VERSION = '0.52_01';
=head1 NAME
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Test/Form.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Test/Form.pm 2012-10-31 03:57:11 UTC (rev 14359)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Test/Form.pm 2012-10-31 03:58:29 UTC (rev 14360)
@@ -7,7 +7,7 @@
__PACKAGE__->mk_accessors(qw( params fields ));
-our $VERSION = '0.52';
+our $VERSION = '0.52_01';
=head1 NAME
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD.pm 2012-10-31 03:57:11 UTC (rev 14359)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD.pm 2012-10-31 03:58:29 UTC (rev 14360)
@@ -4,7 +4,7 @@
use strict;
use Carp;
-our $VERSION = '0.52';
+our $VERSION = '0.52_01';
=head1 NAME
More information about the Catalyst-commits
mailing list