=================================================================== RCS file: /cvs/HOPE/Net-OpenAMD/lib/Net/OpenAMD.pm,v retrieving revision 1.13 retrieving revision 1.16 diff -u -r1.13 -r1.16 --- HOPE/Net-OpenAMD/lib/Net/OpenAMD.pm 2010/06/30 06:30:17 1.13 +++ HOPE/Net-OpenAMD/lib/Net/OpenAMD.pm 2010/07/09 23:04:21 1.16 @@ -1,14 +1,14 @@ package Net::OpenAMD; -# $AFresh1: OpenAMD.pm,v 1.12 2010/06/28 20:32:32 andrew Exp $ +# $AFresh1: OpenAMD.pm,v 1.15 2010/06/30 19:02:48 andrew Exp $ -use version; our $VERSION = qv('0.0.2'); -my $BASE_URI = 'https://api.hope.net/api/'; - use warnings; use strict; use Carp; +use version; our $VERSION = qv('0.0.3'); +my $BASE_URI = 'https://api.hope.net/api/'; + use Scalar::Util qw( refaddr ); *_ident = \&refaddr; @@ -19,7 +19,8 @@ { - my @attr_refs = \( my %base_uri_of, my %ua_of, my %auth_of, ); + my @attr_refs + = \( my %base_uri_of, my %ua_of, my %auth_of, my %actions_of ); sub new { my ( $class, $options ) = @_; @@ -32,7 +33,15 @@ $base_uri_of{$ident} = $options->{base_uri} || $BASE_URI; $ua_of{$ident} = $options->{ua} || LWP::UserAgent->new(); + $actions_of{$ident} = $options->{actions} + || [qw( location speakers talks interests users )]; + foreach my $action ( @{ $actions_of{$ident} } ) { + ## no critic + no strict 'refs'; + *{$action} = sub { shift->get( $action, @_ ) }; + } + # XXX Authenticate return $self; @@ -54,12 +63,7 @@ return @data == 1 ? $data[0] : \@data; } - sub location { return shift->get( 'location', @_ ) } - sub speakers { return shift->get( 'speakers', @_ ) } - sub talks { return shift->get( 'talks', @_ ) } - sub interests { return shift->get( 'interests', @_ ) } - sub users { return shift->get( 'users', @_ ) } - sub stats { croak 'Unused feature' } + sub stats { croak 'Unused feature' } sub DESTROY { my ($self) = @_; @@ -128,7 +132,7 @@ A URL to the API, currently defaults to https://api.hope.net/api/ Most likely it should end with a / to make URI happy, so notice that if you -having 404 errors you don't expect. +are having 404 errors you don't expect. =item ua @@ -169,7 +173,7 @@ =back -Unless specified, there is nothing different about any of the helper methods +Unless specified, there is nothing different about any of the action methods than just calling get($action) instead. Depending on API changes, this may not always be the case.