summaryrefslogtreecommitdiff
path: root/lib/MooseX/Net/API/Meta
diff options
context:
space:
mode:
Diffstat (limited to 'lib/MooseX/Net/API/Meta')
-rw-r--r--lib/MooseX/Net/API/Meta/Method.pm9
-rw-r--r--lib/MooseX/Net/API/Meta/Method/APIDeclare.pm39
-rw-r--r--lib/MooseX/Net/API/Meta/Method/APIMethod.pm13
3 files changed, 25 insertions, 36 deletions
diff --git a/lib/MooseX/Net/API/Meta/Method.pm b/lib/MooseX/Net/API/Meta/Method.pm
index 7c388b9..70ae2c8 100644
--- a/lib/MooseX/Net/API/Meta/Method.pm
+++ b/lib/MooseX/Net/API/Meta/Method.pm
@@ -11,7 +11,7 @@ extends 'Moose::Meta::Method';
subtype UriPath => as 'Str' => where { $_ =~ m!^/! } =>
message {"path must start with /"};
-enum Method => qw(GET POST PUT DELETE);
+enum Method => qw(HEAD GET POST PUT DELETE);
has description => (is => 'ro', isa => 'Str');
has method => (is => 'ro', isa => 'Method', required => 1);
@@ -46,16 +46,13 @@ has required => (
);
before wrap => sub {
- my $class = shift;
- my %args = @_;
-
+ my ($class, %args) = @_;
$class->_validate_params_before_install(\%args);
$class->_validate_required_before_install(\%args);
};
sub wrap {
- my $class = shift;
- my %args = @_;
+ my ($class, %args) = @_;
if (!defined $args{body}) {
my $code = sub {
diff --git a/lib/MooseX/Net/API/Meta/Method/APIDeclare.pm b/lib/MooseX/Net/API/Meta/Method/APIDeclare.pm
index 14fb83d..503ed82 100644
--- a/lib/MooseX/Net/API/Meta/Method/APIDeclare.pm
+++ b/lib/MooseX/Net/API/Meta/Method/APIDeclare.pm
@@ -3,33 +3,26 @@ package MooseX::Net::API::Meta::Method::APIDeclare;
use Moose::Role;
use MooseX::Net::API::Error;
-has options => (
+my @accepted_options = qw/
+ api_base_url
+ api_format
+ api_username
+ api_password
+ authentication
+ authentication_method
+ /;
+
+has api_options => (
is => 'ro',
traits => ['Hash'],
isa => 'HashRef[Str|CodeRef]',
default => sub { {} },
lazy => 1,
handles => {
- set_option => 'set',
- get_option => 'get',
+ set_api_option => 'set',
+ get_api_option => 'get',
},
);
-has accepted_options => (
- is => 'ro',
- traits => ['Array'],
- isa => 'ArrayRef[Str]',
- default => sub {
- [ qw/api_base_url
- api_format
- api_username
- api_password
- authentication
- authentication_method/
- ];
- },
- lazy => 1,
- auto_deref => 1,
-);
sub add_net_api_declare {
my ($meta, $name, %options) = @_;
@@ -38,7 +31,7 @@ sub add_net_api_declare {
die MooseX::Net::API::Error->new(
reason => "'useragent' must be a CODE ref")
unless ref $options{useragent} eq 'CODE';
- $meta->set_option(useragent => delete $options{useragent});
+ $meta->set_api_option(useragent => delete $options{useragent});
}
# XXX for backward compatibility
@@ -49,11 +42,9 @@ sub add_net_api_declare {
}
}
- for my $attr ($meta->accepted_options) {
- $meta->set_option($attr => $options{$attr}) if defined $options{$attr};
+ for my $attr (@accepted_options) {
+ $meta->set_api_option($attr => $options{$attr}) if defined $options{$attr};
}
-
- # XXX before_request after_request
}
1;
diff --git a/lib/MooseX/Net/API/Meta/Method/APIMethod.pm b/lib/MooseX/Net/API/Meta/Method/APIMethod.pm
index d55fe82..0da54b8 100644
--- a/lib/MooseX/Net/API/Meta/Method/APIMethod.pm
+++ b/lib/MooseX/Net/API/Meta/Method/APIMethod.pm
@@ -13,15 +13,15 @@ has local_api_methods => (
default => sub { [] },
auto_deref => 1,
handles => {
- _get_api_method => 'grep',
- _add_api_method => 'push',
- _all_api_methods => 'elements',
+ find_api_method_by_name => 'grep',
+ add_api_method => 'push',
+ get_all_api_methods => 'elements',
},
);
before add_net_api_method => sub {
my ($meta, $name) = @_;
- if (my @method = $meta->_get_api_method(sub {/^$name$/})) {
+ if (my @method = $meta->find_api_method_by_name(sub {/^$name$/})) {
die MooseX::Net::API::Error->new(
reason => "method '$name' is already declared in " . $meta->name);
}
@@ -30,7 +30,8 @@ before add_net_api_method => sub {
sub add_net_api_method {
my ($meta, $name, %options) = @_;
- # accept blessed method
+ # XXX accept blessed method
+
my $code = delete $options{code};
$meta->add_method(
$name,
@@ -41,7 +42,7 @@ sub add_net_api_method {
%options
),
);
- $meta->_add_api_method($name);
+ $meta->add_api_method($name);
}
after add_net_api_method => sub {