diff options
author | Ash Berlin <ash_github@firemirror.com> | 2013-04-19 14:48:57 +0100 |
---|---|---|
committer | Ash Berlin <ash_github@firemirror.com> | 2013-04-19 14:48:57 +0100 |
commit | 87e0a977e5b70ab22fba4eb7b309bd1c92ae8412 (patch) | |
tree | 4b972173b34b4e0651c79a232bc3a6ea9e8b75b3 | |
parent | Don't test pod coverage on release (diff) | |
download | net-http-spore-87e0a977e5b70ab22fba4eb7b309bd1c92ae8412.tar.gz |
Allow _add_methods and _attach_spec_to_class to be subclassed.
For instance I have plans to parse Google's discovery documents which have the right information but are in a different format to SPORE specs.
-rw-r--r-- | Changes | 2 | ||||
-rw-r--r-- | lib/Net/HTTP/Spore.pm | 16 |
2 files changed, 10 insertions, 8 deletions
diff --git a/Changes b/Changes index 3d27d03..0e6c7bf 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,8 @@ ordering in perl 5.17.6+ (#19) - Add support for PATCH HTTP method (#13, Andreas Marienborg) - Allow anonymous subs to be used as middleware (Brian Phillips) + - Refactor internals of Net::HTTP::Spore building of specs to allow easier + subclassing 0.05 Sun Nov 25 11:40:24 2012 - Fix a memory leak in Net::HTTP::Spore::Meta::Method (michaelr) diff --git a/lib/Net/HTTP/Spore.pm b/lib/Net/HTTP/Spore.pm index d4fd8af..d3b2165 100644 --- a/lib/Net/HTTP/Spore.pm +++ b/lib/Net/HTTP/Spore.pm @@ -22,7 +22,7 @@ sub new_from_string { Class::MOP::Class->create_anon_class( superclasses => ['Net::HTTP::Spore::Core'] ); - my $spore_object = _attach_spec_to_class($string, \%args, $spore_class); + my $spore_object = $class->_attach_spec_to_class($string, \%args, $spore_class); return $spore_object; } @@ -42,7 +42,7 @@ sub new_from_strings { my $spore_object = undef; foreach my $string (@strings) { - $spore_object = _attach_spec_to_class($string, $opts, $spore_class, $spore_object); + $spore_object = $class->_attach_spec_to_class($string, $opts, $spore_class, $spore_object); } return $spore_object; } @@ -75,7 +75,7 @@ sub new_from_specs { } sub _attach_spec_to_class { - my ( $string, $opts, $class, $object ) = @_; + my ( $class, $string, $opts, $spore_class, $object ) = @_; my $spec; try { @@ -98,9 +98,9 @@ sub _attach_spec_to_class { } if ( !$object ) { - $object = $class->new_object(%$opts); + $object = $spore_class->new_object(%$opts); } - $object = _add_methods( $object, $spec->{methods} ); + $object = $class->_add_methods( $object, $spec->{methods} ); } catch { Carp::confess( "unable to create new Net::HTTP::Spore object: " . $_ ); @@ -136,13 +136,13 @@ sub _read_spec { } sub _add_methods { - my ($class, $methods_spec) = @_; + my ($class, $spore, $methods_spec) = @_; foreach my $method_name (keys %$methods_spec) { - $class->meta->add_spore_method($method_name, + $spore->meta->add_spore_method($method_name, %{$methods_spec->{$method_name}}); } - $class; + $spore; } 1; |