Created
May 25, 2010 20:32
-
-
Save bobtfish/413648 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use strict; | |
| use warnings; | |
| use Test::More; | |
| use_ok 'MooseX::Types::DuckType::Webframeworks'; | |
| done_testing; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package MooseX::Types::DuckType::Catalyst; | |
| use MooseX::Types -declare => [qw/ | |
| Request | |
| Response | |
| /]; | |
| use Try::Tiny qw/ try /; | |
| use Moose::Util::TypeConstraints; | |
| use MooseX::Types::Moose ':all'; | |
| use namespace::clean -except => [qw/ import unimport /]; | |
| class_type Request, { class => 'Catalyst::Request'}; | |
| class_type Response, {class => 'Catalyst::Response'}; | |
| if (try { require HTTP::Request; require HTTP::Response; }) { | |
| coerce Request, from class_type('HTTP::Request'), as {}; # FIXME }; | |
| coerce Response, from class_type('HTTP::Response'), as {}; # DIXME | |
| } | |
| __PACKAGE__->meta->make_immutable; | |
| 1; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use strict; | |
| use warnings; | |
| use Test::More; | |
| use Catalyst::Request; | |
| use Catalyst::Response; | |
| use MooseX::Types::DuckType::Catalyst qw/ Request Response /; | |
| use Moose::Util::TypeConstraints; | |
| ok find_type_constraint(Request())->check(bless {}, 'Catalyst::Request'); # Dirty.. | |
| ok find_type_constraint(Response())->check(bless {}, 'Catalyst::Response'); | |
| done_testing; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use strict; | |
| use warnings; | |
| use Test::More; | |
| use Catalyst::Request; | |
| use Catalyst::Response; | |
| use HTTP::Headers; | |
| use HTTP::Body; | |
| use MooseX::Types::DuckType::LWP qw/ Request Response /; | |
| use Moose::Util::TypeConstraints; | |
| my $req = Catalyst::Request->new( | |
| method => 'GET', | |
| uri => 'http://www.foo.com/some/path?param=value¶m2=value2', | |
| headers => HTTP::Headers->new('Content-Type' => 'text/plain'), | |
| _body => HTTP::Body->new('text/html', 0), | |
| ); | |
| my $lwp_req = to_Request($req); | |
| ok $lwp_req; | |
| isa_ok $lwp_req, 'HTTP::Request'; | |
| done_testing; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package MooseX::Types::DuckType::LWP; | |
| use MooseX::Types -declare => [qw/ | |
| Request | |
| Response | |
| /]; | |
| use Moose::Util::TypeConstraints; | |
| use Try::Tiny qw/ try /; | |
| use MooseX::Types::Moose ':all'; | |
| use HTTP::Request; | |
| use HTTP::Response; | |
| use namespace::clean -except => [qw/ import unimport /]; | |
| class_type Request, { class => 'HTTP::Request'}; | |
| class_type Response, {class => 'HTTP::Response'}; | |
| if (try { require Catalyst::Request; require Catalyst::Response; }) { | |
| coerce Request, from class_type('Catalyst::Request'), via { | |
| my $req = $_; # FIXME _body probably wrong!! | |
| HTTP::Request->new( map { $req->$_ } qw/ method uri headers _body /); | |
| }; | |
| coerce Response, from class_type('Catalyst::Response'), via {} # FIXME | |
| } | |
| __PACKAGE__->meta->make_immutable; | |
| 1; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use strict; | |
| use warnings; | |
| use Test::More; | |
| use HTTP::Request; | |
| use HTTP::Response; | |
| use MooseX::Types::DuckType::LWP qw/ Request Response /; | |
| use Moose::Util::TypeConstraints; | |
| ok find_type_constraint(Request())->check(bless {}, 'HTTP::Request'); # Dirty.. | |
| ok find_type_constraint(Response())->check(bless {}, 'HTTP::Response'); | |
| done_testing; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package MooseX::Types::DuckType::Webframeworks; | |
| use strict; | |
| use warnings; | |
| our $VERSION = '0.001'; | |
| 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment