[Catalyst-commits] r8019 - in Catalyst-Controller-DBIC-API/1.000/trunk/lib/Catalyst/Controller/DBIC: . API

lukes at dev.catalyst.perl.org lukes at dev.catalyst.perl.org
Fri Jun 27 17:20:19 BST 2008


Author: lukes
Date: 2008-06-27 17:20:19 +0100 (Fri, 27 Jun 2008)
New Revision: 8019

Modified:
   Catalyst-Controller-DBIC-API/1.000/trunk/lib/Catalyst/Controller/DBIC/API.pm
   Catalyst-Controller-DBIC-API/1.000/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm
Log:
added perldoc for config

Modified: Catalyst-Controller-DBIC-API/1.000/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm
===================================================================
--- Catalyst-Controller-DBIC-API/1.000/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm	2008-06-27 15:24:20 UTC (rev 8018)
+++ Catalyst-Controller-DBIC-API/1.000/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm	2008-06-27 16:20:19 UTC (rev 8019)
@@ -19,28 +19,6 @@
   rs_stash_key => 'class_rs'
 );
 
-
-sub end :Private {
-	my ($self, $c) = @_;
-
-	# check for errors
-	my $default_status;
-	if ($self->get_errors($c)) {
-		$c->stash->{response}->{messages} = $self->get_errors($c);
-		$c->stash->{response}->{success} = 'false';
-		$default_status = 400;
-	} else {
-		$c->stash->{response}->{success} = 'true';
-		$default_status = 200;
-	}
-	
-	$c->res->status( $default_status || 200 );
-
-# 	my $json_response = JSON::Syck::Dump($c->stash->{response});
-# 	$c->res->body( $json_response );
-# 	$c->log->debug($c->res->body);
-}
-
 =head2 setup
 
 Just sets $c->stash->{$self->rs_stash_key} to the resultset specified by the 'class' config.
@@ -166,7 +144,6 @@
 	my ($self, $c) = @_;
 
 	return unless ($c->stash->{$self->object_stash_key});
-
 	return $c->stash->{$self->object_stash_key}->delete;
 }
 
@@ -240,7 +217,7 @@
 				}		   			
 			}
 			
-			# TODO: do col type checking here
+			# TODO: do automatic col type checking here
 			
 			# check for multiple values
 			if (ref($value)) {
@@ -248,7 +225,7 @@
 			}
 
 			# check exists so we don't just end up with hash of undefs
-			# check defined to accound for default values being used
+			# check defined to account for default values being used
 			$values{$key} = $value if exists $params->{$key} || defined $value;
 		}
 	}
@@ -258,13 +235,9 @@
 		$self->push_error($c, { message => "No valid keys passed" });
 	}
 
-#	$c->stash->{_save_values}->{$object} = \%values;
 	return ($self->get_errors($c)) ? 0 : \%values;  
 }
 
-sub validate_create { }
-sub validate_update { }
-
 =head2 save_object
 
 =cut
@@ -287,62 +260,23 @@
 	}
 }
 
+sub end :Private {
+	my ($self, $c) = @_;
 
-# =head2 add_to_rel
+	# check for errors
+	my $default_status;
+	if ($self->get_errors($c)) {
+		$c->stash->{response}->{messages} = $self->get_errors($c);
+		$c->stash->{response}->{success} = 'false';
+		$default_status = 400;
+	} else {
+		$c->stash->{response}->{success} = 'true';
+		$default_status = 200;
+	}
+	
+	$c->res->status( $default_status || 200 );
+}
 
-# 	finds a related row and then creates the many_to_many linking row using ->add_to_$rel
-# 	This is a work in progress, it should really allow the related row to also be created
-# 	if it does not already exist.
-
-# =cut
-
-# sub add_to_rel : Chained('object') PathPart('add_to_rel') Args(1) {
-# 	my ($self, $c, $rel) = @_;
-
-# 	my $accessor = "add_to_$rel";
-# 	$self->__rel($c, $rel, $accessor);
-# }
-
-# =head2 remove_from_rel
-
-# 	finds a related row and then removes the many_to_many linking row using ->remove_from_$rel
-
-# =cut
-
-# sub remove_from_rel : Chained('object') PathPart('remove_from_rel') Args(1) {
-# 	my ($self, $c, $rel) = @_;
-
-# 	my $accessor = "remove_from_$rel";
-# 	$self->__rel($c, $rel, $accessor);
-# }
-
-# sub __rel {
-# 	my ($self, $c, $rel, $accessor) = @_;
-
-# 	my $related_rs;
-# 	# pretty grim but i want it to work for many_to_many as well (so not $source->has_relationship)
-# 	eval {
-# 		$related_rs = $c->stash->{$self->object_stash_key}->$rel;
-# 	};
-# 	if ($@) {
-# 		$c->detach( 'error', [{ message => "Invalid relationship $rel" }]);		
-# 	}
-# 	my $source = $related_rs->result_source;
-
-# 	my %related_args = map { $_ => $c->req->params->{$_} } grep { $c->req->params->{$_} } $source->columns;
-
-# 	unless (keys %related_args) {
-# 		$c->detach( 'error', [{ message => "No valid keys passed" }]);
-# 	}
-
-# 	my $related_row = $related_rs->result_source->resultset->find(\%related_args);
-# 	unless ($related_row) {
-# 		$c->detach( 'error', [{ message => "Invalid related row" }]);
-# 	}
-
-# 	$c->stash->{$self->object_stash_key}->$accessor($related_row);
-# }
-
 sub push_error {
 	my ( $self, $c, $params ) = @_;
 

Modified: Catalyst-Controller-DBIC-API/1.000/trunk/lib/Catalyst/Controller/DBIC/API.pm
===================================================================
--- Catalyst-Controller-DBIC-API/1.000/trunk/lib/Catalyst/Controller/DBIC/API.pm	2008-06-27 15:24:20 UTC (rev 8018)
+++ Catalyst-Controller-DBIC-API/1.000/trunk/lib/Catalyst/Controller/DBIC/API.pm	2008-06-27 16:20:19 UTC (rev 8019)
@@ -5,7 +5,7 @@
 
 =head1 VERSION
 
-Version 1.00000
+Version 1.000000
 
 =cut
 
@@ -40,8 +40,43 @@
 
 =head1 GETTING STARTED
 
-See L<Catalyst::Controller::API::Base> for descriptions of base functionlity such as list, create, delete, update and config attributes. Then see L<Catalyst::Controller::API::RPC> or L<Catalyst::Controller::API::REST> for details of provided endpoints on to those base methods.
+See L<Catalyst::Controller::API::Base> for descriptions of base functionlity such as list, create, delete, update and config attributes. Then see L<Catalyst::Controller::API::RPC> or L<Catalyst::Controller::API::REST> for details of provided endpoints to those base methods.
 
+You will need to create a controller for each schema class you need endpoints for. For example if your schema has Artist and Track, and you want to provide a RESTful interface to these, you should create MyApp::Controller::API::REST::Artist and MyApp::Controller::API::REST::Track. You then configure these individually as specified in L</CONFIGURATION>.
+
+=head2 CONFIGURATION
+
+Each of your controller classes needs to be configured to point at the relevant schema class, specify what can be updated and so on, as shown in the L</SYNOPSIS>.
+
+=head2 class
+
+Whatever you would pass to $c->model to get a resultset for this class. MyAppDB::Track for example.
+
+=head2 create_requires
+
+Arrayref listing columns required to be passed to create in order for the request to be valid.
+
+=head2 create_allows
+
+Arrayref listing columns additional to those specified in create_requires that are not required to create but which create does allow. Columns passed to create that are not listed here will be ignored.
+
+=head2 update_allows
+
+Arrayref listing columns that update will allow. Columns passed to update that are not listed here will be ignored.
+
+=head2 list_returns
+
+Arrayref listing columns that list will return. Leave blank to return all columns.
+
+=head2 object_stash_key
+
+Object level methods such as delete and update stash the object in the stash. Specify the stash key you would like to use here. Defaults to 'object'.
+
+=head2 rs_stash_key
+
+List level methods such as list and create stash the class resultset in the stash. Specify the stash key you would like to use here. Defaults to 'class_rs'.
+
+
 =head1 AUTHOR
 
   Luke Saunders <luke.saunders at gmail.com>




More information about the Catalyst-commits mailing list