From: Wallace Reis Date: Thu, 9 Dec 2010 12:41:06 +0000 (+0000) Subject: Add HTTP plugin's doc X-Git-Tag: 0.10~1^2~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-View-Component-SubInclude.git;a=commitdiff_plain;h=b454d9bb2c33864c114f3359fe2e1065133ec4cc Add HTTP plugin's doc --- diff --git a/lib/Catalyst/View/Component/SubInclude/HTTP.pm b/lib/Catalyst/View/Component/SubInclude/HTTP.pm index 35beee5..b876dd2 100644 --- a/lib/Catalyst/View/Component/SubInclude/HTTP.pm +++ b/lib/Catalyst/View/Component/SubInclude/HTTP.pm @@ -9,12 +9,12 @@ use URI; our $VERSION = '0.01'; $VERSION = eval $VERSION; -has ua_timeout => ( - isa => 'Int', is => 'ro', default => 60, +has http_method => ( + isa => 'Str', is => 'ro', default => 'GET', ); -has http_method => ( - isa => 'Str', is => 'ro', required => 1, +has ua_timeout => ( + isa => 'Int', is => 'ro', default => 10, ); has base_uri => ( @@ -95,10 +95,23 @@ In your view class: with 'Catalyst::View::Component::SubInclude'; __PACKAGE__->config( - subinclude_plugin => 'HTTP', + subinclude_plugin => 'HTTP::GET', subinclude => { - HTTP => { - base_uri => 'http://www.foo.com/bar', + 'HTTP::GET' => { + class => 'HTTP', + http_method => 'GET', + ua_timeout => '10', + uri_map => { + '/my/' => 'http://localhost:5000/', + }, + }, + 'HTTP::POST' => { + class => 'HTTP', + http_method => 'POST', + ua_timeout => '10', + uri_map => { + '/foo/' => 'http://www.foo.com/', + }, }, }, ); @@ -106,12 +119,53 @@ In your view class: Then, somewhere in your templates: [% subinclude('/my/widget') %] + ... + [% subinclude_using('HTTP::POST', '/foo/path', { foo => 1 }) %] =head1 DESCRIPTION +C does HTTP requests (currently +using L) and uses the responses to render subinclude contents. + +=head1 CONFIGURATION + +The configuration is passed in the C key based on your plugin name +which can be arbitrary. + +=over + +=item class + +Required just in case your plugin name differs from C. + +=item http_method + +Accepts C and C as values. The default one is C. + +=item user_agent + +This lazily builds a L obj, however you can pass a different +user agent obj that implements the required API. + +=item ua_timeout + +User Agent's timeout config param. Defaults to 10 seconds. + +=item uri_map + +This expects a HashRef in order to map paths to different URLs. + +=item base_uri + +Used only if C is C and defaults to C<< $c->request->base >>. + +=back + =head1 METHODS -=head2 C +=head2 C + +Note that C<$path> should be the relative path. =head1 SEE ALSO