[BACK]Return to OpenAMD.pm CVS log [TXT][DIR] Up to [local] / HOPE / Net-OpenAMD / lib / Net

Diff for /HOPE/Net-OpenAMD/lib/Net/OpenAMD.pm between version 1.5 and 1.6

version 1.5, 2010/06/24 23:57:42 version 1.6, 2010/06/27 01:52:33
Line 1 
Line 1 
 package Net::OpenAMD;  package Net::OpenAMD;
   
 # $AFresh1: OpenAMD.pm,v 1.4 2010/06/24 22:26:55 andrew Exp $  # $AFresh1: OpenAMD.pm,v 1.5 2010/06/24 22:57:42 andrew Exp $
   
 use warnings;  use warnings;
 use strict;  use strict;
Line 13 
Line 13 
 use Class::Std::Utils;  use Class::Std::Utils;
   
 use LWP::UserAgent;  use LWP::UserAgent;
   use URI;
 use Net::OAuth;  use Net::OAuth;
 use JSON::Any;  use JSON::Any;
   
 {  {
   
     my @attr_refs = \();      my @attr_refs = \( my %base_url_of, my %ua_of, my %auth_of, );
   
     sub new {      sub new {
         my ( $class, $options ) = @_;          my ( $class, $options ) = @_;
         my $self = bless anon_scalar(), $class;          my $self = bless anon_scalar(), $class;
         my $ident = ident($self);          my $ident = ident($self);
   
           $options //= {};
   
           croak 'Options should be a hashref' if ref $options ne 'HASH';
   
           $base_url_of{$ident} = $options->{base_url} || $BASE_URL;
           $ua_of{$ident}       = $options->{ua}       || LWP::UserAgent->new();
   
           # XXX Authenticate
   
         return $self;          return $self;
     }      }
   
     sub _get { croak 'Unsupported' }      sub _get {
           my ( $self, $action, $query ) = @_;
           my $ident = ident($self);
   
           my $uri = URI->new( $base_url_of{$ident} . '/' . $action );
           $uri->query($query);
   
           my $response = $ua_of{$ident}->get($uri);
   
           if ( !$response->is_success ) {
               croak $response->status_line;
           }
   
           return JSON::Any->jsonToObj( $response->decoded_content );
       }
   
     sub location  { my $self = shift; return $self->_get( 'location',  @_ ) }      sub location  { my $self = shift; return $self->_get( 'location',  @_ ) }
     sub speakers  { my $self = shift; return $self->_get( 'speakers',  @_ ) }      sub speakers  { my $self = shift; return $self->_get( 'speakers',  @_ ) }
     sub talks     { my $self = shift; return $self->_get( 'talks',     @_ ) }      sub talks     { my $self = shift; return $self->_get( 'talks',     @_ ) }
     sub interests { my $self = shift; return $self->_get( 'interests', @_ ) }      sub interests { my $self = shift; return $self->_get( 'interests', @_ ) }
     sub users     { my $self = shift; return $self->_get( 'users',     @_ ) }      sub users     { my $self = shift; return $self->_get( 'users',     @_ ) }
     sub stats { croak 'Unused feature' }      sub stats { croak 'Unused feature' }
   
       sub DESTROY {
           my ($self) = @_;
           my $ident = ident $self;
   
           foreach my $attr_ref (@attr_refs) {
               delete $attr_ref->{$ident};
           }
   
           return;
       }
   
 }  }
   
 1;    # Magic true value required at end of module  1;    # Magic true value required at end of module

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>