Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Switched from BUILD to BUILDARGS

  • Loading branch information...
commit 7ffe4cd915d0de12df20b4eaf2bfdbd5b311d702 1 parent 7ee66e4
@symkat authored
View
2  lib/WebService/CloudFlare/Host.pm
@@ -124,7 +124,7 @@ sub _create_response {
);
};
- return "WebService::CloudFlare::Host::Response::$class"->new( http => $http );
+ return "WebService::CloudFlare::Host::Response::$class"->new( $http );
}
View
69 lib/WebService/CloudFlare/Host/Response/UserCreate.pm
@@ -1,7 +1,6 @@
package WebService::CloudFlare::Host::Response::UserCreate;
use Moose;
use JSON;
-use Data::Dumper;
sub map {
return (
@@ -24,67 +23,27 @@ has 'user_key' => ( is => 'rw', isa => 'Str', required => 0 );
has 'username' => ( is => 'rw', isa => 'Str', required => 0 );
has 'unique_id' => ( is => 'rw', isa => 'Str', required => 0 );
-has 'http' => ( is => 'ro', isa => 'HTTP::Response', required => 1, clearer => 'unset_http' );
-
-1;
-
-sub BUILD {
- my ( $self ) = @_;
-
- die "HTTP Status " . $self->http->code . " returned, expected 200."
- unless $self->http->code == 200;
-
- my $json = decode_json( $self->http->content );
-
- my %map = $self->map;
-
- for my $key ( keys %map ) {
- my ( @elems ) = split(":", $map{$key});
-
- # This is dumb, how do I make it less dumb?
- if ( @elems == 1 ) {
- $self->$key( $json->{$elems[0]} )
- if exists $json->{$elems[0]};
- } elsif ( @elems == 2 ) {
- $self->$key( $json->{$elems[0]}->{$elems[1]})
- if exists $json->{$elems[0]}->{$elems[1]};
- } elsif ( @elems == 3 ) {
- $self->$key( $json->{$elems[0]}->{$elems[1]}->{$elems[2]})
- if exists $json->{$elems[0]}->{$elems[1]}->{$elems[2]};
- }
- }
-
- $self->unset_http;
-
-}
-
-__END__
sub BUILDARGS {
- my ( $class, $orig, $http ) = @_;
- print Dumper $class;
- print DUmper $http;
- my %new;
-
+ my ( $class, $http ) = @_;
+
die "HTTP Status " . $http->code . " returned, expected 200."
unless $http->code == 200;
my $json = decode_json( $http->content );
-
my %map = $class->map;
-
- for my $key ( keys %map ) {
- my ( @elems ) = split(":", $map{$key});
-
- # This is dumb, how do I make it less dumb?
- if ( @elems == 1 ) {
- $new{$key} = $json->{$elems[0]};
- } elsif ( @elems == 2 ) {
- $new{$key} = $json->{$elems[0]}->{$elems[1]};
- } elsif ( @elems == 3 ) {
- $new{$key} = $json->{$elems[0]}->{$elems[1]}->{$elems[2]};
+ my $args = {};
+
+ OUTER: for my $key ( keys %map ) {
+ my ( @elems ) = split( ":", $map{$key} );
+ my $tmp_json = $json;
+ for my $elem ( @elems ) {
+ next OUTER unless exists $tmp_json->{$elem};
+ $tmp_json = $tmp_json->{$elem};
}
+ $args->{$key} = $tmp_json;
+ #$self->$key($tmp_json);
}
- return $class->new(%new);
- #return $class->$orig(%new);
+ return $args;
}
+
1;
Please sign in to comment.
Something went wrong with that request. Please try again.