[Catalyst-commits] r14369 - in
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD: . Model
karpet at dev.catalyst.perl.org
karpet at dev.catalyst.perl.org
Wed Oct 31 19:18:53 GMT 2012
Author: karpet
Date: 2012-10-31 19:18:53 +0000 (Wed, 31 Oct 2012)
New Revision: 14369
Modified:
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model/File.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/REST.pm
Log:
fix failing File tests, support REST view_related in RPC-compat mode
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 18:13:32 UTC (rev 14368)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model/File.pm 2012-10-31 19:18:53 UTC (rev 14369)
@@ -224,6 +224,25 @@
return CatalystX::CRUD::Iterator::File->new($files);
}
+=head2 iterator_related( I<file>, I<rel_name> )
+
+Required method. Acts like iterator() for I<rel_name>.
+
+=cut
+
+sub iterator_related {
+ my $self = shift;
+ my $file = shift or $self->throw_error('file required');
+ my $rel_name = shift or $self->throw_error('rel_name required');
+ if ( $rel_name eq 'dir' ) {
+ my $files = $self->search(@_);
+ return CatalystX::CRUD::Iterator::File->new($files);
+ }
+ else {
+ $self->throw_error("unsupported relationship name: $rel_name");
+ }
+}
+
=head2 add_related( I<file>, I<rel_name>, I<other_file_name> )
For I<rel_name> of "dir" will create a symlink for I<other_file_name>'s
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/REST.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/REST.pm 2012-10-31 18:13:32 UTC (rev 14368)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/REST.pm 2012-10-31 19:18:53 UTC (rev 14369)
@@ -139,7 +139,7 @@
my %rpc_methods
= map { $_ => 1 } qw( create read update delete edit save rm view );
my %related_methods
- = map { $_ => 1 } qw( add remove list_related view_related );
+ = map { $_ => 1 } qw( add remove list_related view_related view );
sub rest : Path {
my ( $self, $c, @arg ) = @_;
@@ -202,6 +202,7 @@
if ($rpc) {
if ( !$self->enable_rpc_compat or !exists $related_methods{$rpc} ) {
+ $c->log->debug("unmapped rpc:$rpc") if $c->debug;
$self->_set_status_404($c);
return;
}
@@ -212,6 +213,11 @@
my $rpc_method;
if ($rpc) {
$rpc_method = $rpc;
+
+ # mimic PathPart
+ if ( $rpc_method eq 'view' ) {
+ $rpc_method = 'view_related';
+ }
}
elsif ( $http_method eq 'POST' or $http_method eq 'PUT' ) {
$rpc_method = 'add';
@@ -261,11 +267,11 @@
if $c->debug;
if ( length $oid and $rpc ) {
- if ( exists $rpc_methods{$rpc} ) {
+ if ( $self->enable_rpc_compat and exists $rpc_methods{$rpc} ) {
# do nothing - logic below
}
- elsif ( $http_method eq 'GET' ) {
+ elsif ( $self->enable_rpc_compat and $http_method eq 'GET' ) {
# same logic as !length $oid below:
# assume that $rpc is a relationship name
More information about the Catalyst-commits
mailing list