Catalyst-Plugin-ResponseFrom

 view release on metacpan or  search on metacpan

META.yml  view on Meta::CPAN

---
abstract: 'Get the response from a public path.'
author:
  - 'John Napiorkowski <jjnapiork@cpan.org>'
build_requires:
  HTTP::Request::Common: '0'
  Test::Most: '0'
configure_requires:
  ExtUtils::MakeMaker: '0'
dynamic_config: 0
generated_by: 'Dist::Zilla version 5.037, CPAN::Meta::Converter version 2.150001'
license: perl
meta-spec:
  url: http://module-build.sourceforge.net/META-spec-v1.4.html
  version: '1.4'
name: Catalyst-Plugin-ResponseFrom

Makefile.PL  view on Meta::CPAN

  "NAME" => "Catalyst::Plugin::ResponseFrom",
  "PREREQ_PM" => {
    "Catalyst" => "5.90060",
    "HTTP::Message::PSGI" => 0,
    "MIME::Base64" => 0,
    "Moose::Role" => 0,
    "Scalar::Util" => 0,
    "URI" => 0
  },
  "TEST_REQUIRES" => {
    "HTTP::Request::Common" => 0,
    "Test::Most" => 0
  },
  "VERSION" => "0.003",
  "test" => {
    "TESTS" => "t/*.t"
  }
);


my %FallbackPrereqs = (
  "Catalyst" => "5.90060",
  "ExtUtils::MakeMaker" => 0,
  "HTTP::Message::PSGI" => 0,
  "HTTP::Request::Common" => 0,
  "MIME::Base64" => 0,
  "Moose::Role" => 0,
  "Scalar::Util" => 0,
  "Test::Most" => 0,
  "URI" => 0
);


unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) {
  delete $WriteMakefileArgs{TEST_REQUIRES};

README.mkdn  view on Meta::CPAN


    package MyApp;
    use Catalyst 'ResponseFrom';

    MyApp->setup;

    package MyApp::Controller::Example;

    use Moose;
    use MooseX::MethodAttributes;
    use HTTP::Request::Common;

    extends 'Catalyst::Controller';

    sub as_http_request :Local {
      my ($self, $c) = @_;
      $c->redispatch_to(GET $c->uri_for($self->action_for('target')));
    }

    sub as_spec :Local {
      my ($self, $c) = @_;

README.mkdn  view on Meta::CPAN


This plugin adds the following methods to your [Catalyst](https://metacpan.org/pod/Catalyst) application.  All methods
share the same function signature (this approach and following documentation 'borrowed'
from [Web::Simple](https://metacpan.org/pod/Web::Simple)):

       my $psgi_response = $app->http_response_from(GET => '/' => %headers);
       my $http_response = $app->http_response_from(POST => '/' => %headers_or_form);
       $c->redispatch_to($http_request);
    

Accepts either an [HTTP::Request](https://metacpan.org/pod/HTTP::Request) object or ($method, $path) and runs that
request against the application, returning an [HTTP::Response](https://metacpan.org/pod/HTTP::Response) object.

If the HTTP method is POST or PUT, then a series of pairs can be passed after
this to create a form style message body. If you need to test an upload, then
create an [HTTP::Request](https://metacpan.org/pod/HTTP::Request) object by hand or use the `POST` subroutine
provided by [HTTP::Request::Common](https://metacpan.org/pod/HTTP::Request::Common).

If you prefix the URL with 'user:pass@' this will be converted into
an Authorization header for HTTP basic auth:

     my $res = $app->http_response_from(
                 GET => 'bob:secret@/protected/resource'
               );
    

If pairs are passed where the key ends in :, it is instead treated as a

dist.ini  view on Meta::CPAN

[Prereqs]
Catalyst = 5.90060
HTTP::Message::PSGI = 0
Moose::Role = 0
MIME::Base64 = 0
URI = 0
Scalar::Util = 0

[Prereqs / TestRequires]
Test::Most = 0
HTTP::Request::Common = 0

lib/Catalyst/Plugin/ResponseFrom.pm  view on Meta::CPAN

package Catalyst::Plugin::ResponseFrom;

use URI ();
use Moose::Role;
use HTTP::Message::PSGI ();
use MIME::Base64 ();
use HTTP::Request ();
use Scalar::Util ();

our $VERSION = '0.003';

requires 'psgi_app', 'res', 'detach';

## Block of code gratuitously stolen from Web::Simple::Application
my $_request_spec_to_http_request = sub {
  my ($self, $method, $path, @rest) = @_;

  # if the first arg is a catalyst action, build a URL
  if(Scalar::Util::blessed $method and $method->isa('Catalyst::Action')) {
    $path = $self->uri_for($method, @_[2..$#_]);
    $method = 'GET';
    @rest = ();
  }

  # if it's a reference, assume a request object
  return $method if(Scalar::Util::blessed $method and $method->isa('HTTP::Request'));
 
  if ($path =~ s/^(.*?)\@//) {
    my $basic = $1;
    unshift @rest, 'Authorization:', 'Basic '.MIME::Base64::encode($basic);
  }
 
  my $request = HTTP::Request->new($method => $path);
 
  my @params;
 
  while (my ($header, $value) = splice(@rest, 0, 2)) {
    unless ($header =~ s/:$//) {
      push @params, $header, $value;
    }
    $header =~ s/_/-/g;
    if ($header eq 'Content') {
      $request->content($value);

lib/Catalyst/Plugin/ResponseFrom.pm  view on Meta::CPAN


    package MyApp;
    use Catalyst 'ResponseFrom';

    MyApp->setup;

    package MyApp::Controller::Example;

    use Moose;
    use MooseX::MethodAttributes;
    use HTTP::Request::Common;

    extends 'Catalyst::Controller';

    sub as_http_request :Local {
      my ($self, $c) = @_;
      $c->redispatch_to(GET $c->uri_for($self->action_for('target')));
      # For simple GETs you can just use $c->uri_for style params like:
      $c->redispatch_to($self->action_for('target'));
    }

lib/Catalyst/Plugin/ResponseFrom.pm  view on Meta::CPAN

from L<Web::Simple>):

    my $psgi_response = $app->http_response_from(GET => '/' => %headers);
    my $http_response = $app->http_response_from(POST => '/' => %headers_or_form);
    $c->redispatch_to($http_request);

Accept three style of arguments:

=over4

=item  An L<HTTP::Request> object

Runs this against the application as if running from a client such as a browser

=item Parameters ($method, $path) 

A single domain specific language used to construct an L<HTTP::Request> object.

If the HTTP method is POST or PUT, then a series of pairs can be passed after
this to create a form style message body. If you need to test an upload, then
create an L<HTTP::Request> object by hand or use the C<POST> subroutine
provided by L<HTTP::Request::Common>.
 
If you prefix the URL with 'user:pass@' this will be converted into
an Authorization header for HTTP basic auth:
 
    my $res = $app->http_response_from(
                GET => 'bob:secret@/protected/resource'
              );
   
If pairs are passed where the key ends in :, it is instead treated as a
headers, so:

t/basic.t  view on Meta::CPAN

use Test::Most;

{
  package MyApp::Controller::Example;
  $INC{'MyApp/Controller/Example.pm'} = __FILE__;

  use base 'Catalyst::Controller';
  use HTTP::Request::Common;
   
  sub as_http_request :Local {
    my ($self, $c) = @_;
    $c->redispatch_to(GET $c->uri_for($self->action_for('target')));
  }

  sub as_spec :Local {
    my ($self, $c) = @_;
    $c->redispatch_to(GET => $c->uri_for($self->action_for('target')));
  }



( run in 0.567 second using v1.01-cache-2.11-cpan-de7293f3b23 )