[Catalyst] How to do REST without deserializing uploaded files (PUT)

2009-03-31 Thread Bruce McKenzie

I have a controller subclassed from Catalyst::Controller::REST.

Most of my methods are happily ActionClass('REST')'d, but I have one  
where I want a file to be uploaded and NOT
deserialized. Even if I did not include the ActionClass attribute, I  
would get a complaint about no deserialization method for the upload.


I couldn't figure out how to do it, so I backed out the RESTness from  
the controller and implemented a straight put method:


sub xxx :Local :Args(0) {
my ( $self, $c ) = @_;

return if $c-request-method ne 'PUT';

my $filecontents = '';

my ($fh) = $c-request-body;
while ( my $line = $fh )
{
$filecontents .= $line;
}

 do something with it ...

$c-response-status('202');
$c-response-body( stuff accepted );

}

Is there a way to declare some paths as NOT subject to  
deserialization? The reason I ask is that I want it for most  
everything...just not for a few paths.


(Incidentally, am I doing the right thing to get the file contents? It  
seems to work and I can't find any other doc/pointers)


FWIW I was using curl to test it:

curl -T somefile  http://localhost:3000/demo/xxx

Thanks very much!

Bruce

---
Bruce McKenzie
bru...@dynamicrange.com



___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] How to do REST without deserializing uploaded files (PUT)

2009-03-31 Thread Hans Dieter Pearcey
On Tue, Mar 31, 2009 at 09:03:15PM -0700, Bruce McKenzie wrote:
 Is there a way to declare some paths as NOT subject to deserialization? The
 reason I ask is that I want it for most everything...just not for a few paths.

Instead of deserializing in begin() (as C::C::REST does for you), this might
work:

  sub deserialize : Chained(/) PathPart('') ActionClass(Deserialize) {}

  sub foo : Chained(deserialize) ActionClass(REST) {}
  sub foo_POST {...} # etc.

  sub bar : ActionClass(REST) {}
  sub bar_PUT {...} # etc.

foo comes from the deserialize action, bar doesn't, so a PUT to /bar won't
trigger deserialization. (note: totally untested.)

In the future, when we all have flying cars, REST and Deserialize will be
action roles, and you can do:

  sub foo : Does(REST) Does(Deserialize) {}
  sub foo_POST {...}

  sub bar : Does(REST) {}
  sub bar_PUT {...}

I'm open to other suggestions.

hdp.

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/