summaryrefslogtreecommitdiff
path: root/lib/MooseX/Net/API
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2009-12-08 16:13:54 +0100
committerfranck cuny <franck@lumberjaph.net>2009-12-08 16:13:54 +0100
commit100caaf831eb877adecce830fe7f83c7b3d37080 (patch)
treedb03a6d673457919f42feefe1d56eb85e16efb77 /lib/MooseX/Net/API
parentmethod to deserialize (diff)
downloadmoosex-net-api-100caaf831eb877adecce830fe7f83c7b3d37080.tar.gz
update tests to use catalyst, bla
Diffstat (limited to 'lib/MooseX/Net/API')
-rw-r--r--lib/MooseX/Net/API/Role/CatalystTest.pm57
-rw-r--r--lib/MooseX/Net/API/Test.pm46
2 files changed, 59 insertions, 44 deletions
diff --git a/lib/MooseX/Net/API/Role/CatalystTest.pm b/lib/MooseX/Net/API/Role/CatalystTest.pm
new file mode 100644
index 0000000..d81b956
--- /dev/null
+++ b/lib/MooseX/Net/API/Role/CatalystTest.pm
@@ -0,0 +1,57 @@
+package MooseX::Net::API::Role::CatalystTest;
+
+use lib ('t/lib');
+use Moose::Role; with qw/
+ MooseX::Net::API::Role::Serialize
+ MooseX::Net::API::Role::Deserialize/;
+
+my $list_content_type = {
+ 'json' => 'application/json',
+ 'yaml' => 'text/x-yaml',
+ 'xml' => 'text/xml',
+};
+
+after qw/test_api_declare/ => sub {
+ my $caller = shift;
+ my $name = shift;
+ my %options = @_;
+
+ if ( $options{catalyst} ) {
+ my $app = $options{catalyst_app_name};
+
+ Class::MOP::load_class("HTTP::Request");
+ Class::MOP::load_class("Catalyst::Test");
+
+ Catalyst::Test->import($app);
+
+ my $res = __PACKAGE__->meta->remove_method('_request');
+ MooseX::Net::API->meta->add_method(
+ '_request' => sub {
+ my ( $class, $format, $options, $uri, $args ) = @_;
+ my $method = $options->{method};
+
+ my $res;
+ if ( $method =~ /^(?:GET|DELETE)$/
+ || $options->{params_in_url} )
+ {
+ $uri->query_form(%$args);
+ my $req = HTTP::Request->new( $method => $uri );
+ $req->header(
+ 'Content-Type' => $list_content_type->{$format} );
+ $res = request($req);
+ }
+ else {
+ my $req = HTTP::Request->new( $method => $uri );
+ $req->header(
+ 'Content-Type' => $list_content_type->{$format} );
+ my $content = _do_serialization($class, $args, $format);
+ $req->content( $content );
+ $res = request($req);
+ }
+ return $res;
+ }
+ );
+ }
+};
+
+1;
diff --git a/lib/MooseX/Net/API/Test.pm b/lib/MooseX/Net/API/Test.pm
index e991b7f..dbd4349 100644
--- a/lib/MooseX/Net/API/Test.pm
+++ b/lib/MooseX/Net/API/Test.pm
@@ -9,6 +9,8 @@ use Moose::Exporter;
use MooseX::Net::API::Meta::Class;
use MooseX::Net::API::Meta::Method;
+with qw/MooseX::Net::API::Role::CatalystTest/;
+
Moose::Exporter->setup_import_methods(
with_caller => [qw/test_api_method test_api_declare run/] );
@@ -24,14 +26,6 @@ sub init_meta {
);
}
-my $list_content_type = {
- 'json' => 'application/json',
- 'yaml' => 'text/x-yaml',
- 'xml' => 'text/xml',
-};
-
-my $tests_count = 0;
-
sub test_api_declare {
my $caller = shift;
my $name = shift;
@@ -42,42 +36,6 @@ sub test_api_declare {
}
$api_to_test = $name;
-
- if ( $options{catalyst} ) {
- my $app = $options{catalyst_app_name};
-
- Class::MOP::load_class("HTTP::Request");
- Class::MOP::load_class("Catalyst::Test");
-
- Catalyst::Test->import($app);
-
- my $res = __PACKAGE__->meta->remove_method('_request');
- MooseX::Net::API->meta->add_method(
- '_request' => sub {
- my ( $class, $format, $options, $uri, $args ) = @_;
- my $method = $options->{method};
-
- my $res;
- if ( $method =~ /^(?:GET|DELETE)$/
- || $options->{params_in_url} )
- {
- $uri->query_form(%$args);
- my $req = HTTP::Request->new( $method => $uri );
- $req->header(
- 'Content-Type' => $list_content_type->{$format} );
- $res = request($req);
- }
- else {
- my $req = HTTP::Request->new( $method => $uri );
- $req->header(
- 'Content-Type' => $list_content_type->{$format} );
- $req->header( 'Content' => Dump $args);
- $res = request($req);
- }
- return $res;
- }
- );
- }
}
sub test_api_method {