From c94d18646c9116502cfb212de1ab9f8df2377b90 Mon Sep 17 00:00:00 2001 From: franck cuny Date: Thu, 3 Jun 2010 14:11:54 +0200 Subject: rename some methods --- lib/MooseX/Net/API/Meta/Method.pm | 9 +++---- lib/MooseX/Net/API/Meta/Method/APIDeclare.pm | 39 +++++++++++----------------- lib/MooseX/Net/API/Meta/Method/APIMethod.pm | 13 +++++----- lib/MooseX/Net/API/Role/Authentication.pm | 6 ++--- lib/MooseX/Net/API/Role/Format.pm | 4 +-- lib/MooseX/Net/API/Role/Request.pm | 2 +- lib/MooseX/Net/API/Role/UserAgent.pm | 2 +- 7 files changed, 32 insertions(+), 43 deletions(-) (limited to 'lib') 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 { diff --git a/lib/MooseX/Net/API/Role/Authentication.pm b/lib/MooseX/Net/API/Role/Authentication.pm index 0b6de69..7f741b3 100644 --- a/lib/MooseX/Net/API/Role/Authentication.pm +++ b/lib/MooseX/Net/API/Role/Authentication.pm @@ -20,12 +20,12 @@ after BUILDALL => sub { for (qw/api_username api_password/) { my $predicate = 'has_' . $_; - my $value = $self->meta->get_option($_); + my $value = $self->meta->get_api_option($_); $self->$_($value) if $value && !$self->$predicate; } - if (my $has_auth = $self->meta->get_option('authentication')) { - my $auth_method = $self->meta->get_option('authentication_method'); + if (my $has_auth = $self->meta->get_api_option('authentication')) { + my $auth_method = $self->meta->get_api_option('authentication_method'); if ($auth_method) { $self->api_useragent->add_handler( request_prepare => sub { $self->$auth_method(@_) }); diff --git a/lib/MooseX/Net/API/Role/Format.pm b/lib/MooseX/Net/API/Role/Format.pm index e766161..37956bb 100644 --- a/lib/MooseX/Net/API/Role/Format.pm +++ b/lib/MooseX/Net/API/Role/Format.pm @@ -23,7 +23,7 @@ has api_format => ( lazy => 1, default => sub { my $self = shift; - $self->meta->get_option('api_format'); + $self->meta->get_api_option('api_format'); } ); @@ -33,7 +33,7 @@ has api_format_mode => ( lazy => 1, default => sub { my $self = shift; - my $mode = $self->meta->get_option('api_format_mode'); + my $mode = $self->meta->get_api_option('api_format_mode'); $mode || 'append'; } ); diff --git a/lib/MooseX/Net/API/Role/Request.pm b/lib/MooseX/Net/API/Role/Request.pm index 214411c..3b97da6 100644 --- a/lib/MooseX/Net/API/Role/Request.pm +++ b/lib/MooseX/Net/API/Role/Request.pm @@ -12,7 +12,7 @@ has api_base_url => ( lazy => 1, default => sub { my $self = shift; - my $api_base_url = $self->meta->get_option('api_base_url'); + my $api_base_url = $self->meta->get_api_option('api_base_url'); if (!$api_base_url) { die MooseX::Net::API::Error->new( reason => "'api_base_url' have not been defined"); diff --git a/lib/MooseX/Net/API/Role/UserAgent.pm b/lib/MooseX/Net/API/Role/UserAgent.pm index c3a1d5b..c21628a 100644 --- a/lib/MooseX/Net/API/Role/UserAgent.pm +++ b/lib/MooseX/Net/API/Role/UserAgent.pm @@ -9,7 +9,7 @@ has api_useragent => ( lazy => 1, default => sub { my $self = shift; - my $ua = $self->meta->get_option('useragent'); + my $ua = $self->meta->get_api_option('useragent'); return $ua->() if $ua; $ua = LWP::UserAgent->new(); $ua->agent( -- cgit 1.4.1