| 1 | package PX::API::Response; | ||
| 2 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 2 | ▶ | use Carp; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 2 | ▶ | use version; our $VERSION = qv('0.0.3'); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 2 | ▶ | use HTTP::Response; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | our @ISA = qw(HTTP::Response); | ||
| 10 | |||
| 11 | use Module::Pluggable::Fast | ||
| 12 | 0 | ▶ | name => 'response_plugins', |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 13 | 0 | search => [ qw/PX::API::Response/ ]; | |
| 14 | |||
| 15 | |||
| 16 | sub new { | ||
| 17 | my $class = shift; | ||
| 18 | my $args = shift; | ||
| 19 | |||
| 20 | my $self = HTTP::Response->new(); | ||
| 21 | return bless $self, $class; | ||
| 22 | } | ||
| 23 | |||
| 24 | sub _init { | ||
| 25 | my $self = shift; | ||
| 26 | my $args = shift; | ||
| 27 | my $format = $args->{'format'} || "rest"; | ||
| 28 | |||
| 29 | my @classes = $self->response_plugins; | ||
| 30 | foreach my $c(@classes) { | ||
| 31 | if ($c->format eq $format) { | ||
| 32 | $self->{'parser'} = $c; | ||
| 33 | last; | ||
| 34 | } | ||
| 35 | } | ||
| 36 | return $self; | ||
| 37 | } | ||
| 38 | |||
| 39 | sub fault { | ||
| 40 | my ($self,$err_code,$err_string) = @_; | ||
| 41 | $self->{success} = 0; | ||
| 42 | $self->{err_code} = $err_code; | ||
| 43 | $self->{err_string} = $err_string; | ||
| 44 | } | ||
| 45 | |||
| 46 | sub success { | ||
| 47 | my ($self,$ref) = @_; | ||
| 48 | $self->{success} = 1; | ||
| 49 | $self->{response} = $ref; | ||
| 50 | } | ||
| 51 | |||
| 52 | |||
| 53 | 1; | ||
| 54 | __END__ | ||