summary refs log tree commit diff
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-09-15 18:15:50 +0200
committerfranck cuny <franck@lumberjaph.net>2010-09-15 18:15:50 +0200
commit050b91bff38310afa18ff616aa739e4c18affc7b (patch)
tree89ae6966c0e20b04864b7057d4d6e62df5259121
parentapi attributes (diff)
downloadnet-http-spore-050b91bff38310afa18ff616aa739e4c18affc7b.tar.gz
init. object with api attributes
-rw-r--r--lib/Net/HTTP/Spore.pm28
1 files changed, 19 insertions, 9 deletions
diff --git a/lib/Net/HTTP/Spore.pm b/lib/Net/HTTP/Spore.pm
index b70bd31..4ee6ac3 100644
--- a/lib/Net/HTTP/Spore.pm
+++ b/lib/Net/HTTP/Spore.pm
@@ -14,13 +14,13 @@ use Net::HTTP::Spore::Core;
 our $VERSION = 0.01;
 
 sub new_from_spec {
-    my ($class, $spec_file, %args) = @_;
+    my ( $class, $spec_file, %args ) = @_;
 
-    unless (-f $spec_file) {
-        Carp::confess ("$spec_file does not exists");
+    unless ( -f $spec_file ) {
+        Carp::confess("$spec_file does not exists");
     }
 
-    my ($content, $spec);
+    my ( $content, $spec );
 
     $content < io($spec_file);
 
@@ -31,13 +31,13 @@ sub new_from_spec {
         Carp::confess( "unable to parse JSON spec: " . $_ );
     };
 
-    my ($spore_class, $spore_object);
+    my ( $spore_class, $spore_object );
 
     # XXX should we let the possibility to override this super class, or add
     # another superclasses?
     $spore_class =
       Class::MOP::Class->create_anon_class(
-          superclasses => ['Net::HTTP::Spore::Core']);
+        superclasses => ['Net::HTTP::Spore::Core'] );
 
     try {
         my $api_base_url;
@@ -48,16 +48,26 @@ sub new_from_spec {
             die "api_base_url is missing!";
         }
 
+        if ( $spec->{api_format} ) {
+            $args{api_format} = $spec->{api_format};
+        }
+
+        if ( $spec->{authentication} ) {
+            $args{authentication} = $spec->{authentication};
+        }
+
         $spore_object = $spore_class->new_object(%args);
-        $spore_object = _add_methods($spore_object, $spec->{methods});
+        $spore_object = _add_methods( $spore_object, $spec->{methods} );
 
-    }catch{
-        Carp::confess("unable to create new Net::HTTP::Spore object: ".$_);
+    }
+    catch {
+        Carp::confess( "unable to create new Net::HTTP::Spore object: " . $_ );
     };
 
     return $spore_object;
 }
 
+
 sub _add_methods {
     my ($class, $methods_spec) = @_;