X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=lib%2FMaypole%2FManual%2FRequest.pod;h=0aa333a6c22be22cf3ea03f2a54bff9336b574b2;hb=db969aff8709f53ce4c7494166feb308008264e0;hp=d3d66f299c66d6116d27c2ba1dba747b23226471;hpb=628ecd5d9d294e601c79c7509140d02dcd7a1d40;p=maypole.git diff --git a/lib/Maypole/Manual/Request.pod b/lib/Maypole/Manual/Request.pod index d3d66f2..0aa333a 100644 --- a/lib/Maypole/Manual/Request.pod +++ b/lib/Maypole/Manual/Request.pod @@ -1,4 +1,8 @@ -=head1 Maypole Request Hacking Cookbook +=head1 NAME + +Maypole::Manual::Request - Maypole Request Hacking Cookbook + +=head1 DESCRIPTION Hacks; design patterns; recipes: call it what you like, this chapter is a developing collection of techniques which can be slotted in to Maypole @@ -598,16 +602,21 @@ to the original C routine. For instance, in this method, we use a L object to fill in some fields of a database row based on an ISBN: + use Net::Amazon; + my $amazon = Net::Amazon->new(token => 'YOUR_AMZN_TOKEN'); + + ... + sub create_from_isbn :Exported { my ($self, $r) = @_; - my $response = $ua->search(asin => $r->params->{isbn}); - my ($prop) = $response->properties; + my $book_info = $amazon->search(asin => $r->params->{isbn})->properties; + # Rewrite the CGI parameters with the ones from Amazon - @{$r->params->{qw(title publisher author year)} = - ($prop->title, - $prop->publisher, - (join "/", $prop->authors()), - $prop->year()); + $r->params->{title} = $book_info->title; + $r->params->{publisher} = $book_info->publisher; + $r->params->{year} = $book_info->year; + $r->params->{author} = join('and', $book_info->authors()); + # And jump to the usual edit/create routine $self->do_edit($r); }