equal
deleted
inserted
replaced
|
1 package Joker::Result; |
|
2 use Moose; |
|
3 use MooseX::SemiAffordanceAccessor; |
|
4 |
|
5 has response => (is => 'ro', isa => 'Str'); |
|
6 |
|
7 has fields => ( |
|
8 is => 'ro', |
|
9 isa => 'ArrayRef', |
|
10 lazy => 1, |
|
11 init_arg => undef, |
|
12 builder => '_fields' |
|
13 ); |
|
14 |
|
15 has status => ( |
|
16 is => 'ro', |
|
17 lazy => 1, |
|
18 init_arg => undef, |
|
19 builder => '_status' |
|
20 ); |
|
21 |
|
22 has data => ( |
|
23 is => 'ro', |
|
24 isa => 'HashRef', |
|
25 lazy => 1, |
|
26 init_arg => undef, |
|
27 builder => '_data', |
|
28 ); |
|
29 |
|
30 has fields => ( |
|
31 is => 'ro', |
|
32 isa => 'ArrayRef', |
|
33 lazy => 1, |
|
34 init_arg => undef, |
|
35 default => sub { sort keys %{ $_[0]->data } }, |
|
36 ); |
|
37 |
|
38 has code => ( |
|
39 is => 'ro', |
|
40 isa => 'Int', |
|
41 lazy => 1, |
|
42 init_arg => undef, |
|
43 default => sub { $_[0]->data->{'status-code'} }, |
|
44 ); |
|
45 |
|
46 has status => ( |
|
47 is => 'ro', |
|
48 isa => 'Str', |
|
49 lazy => 1, |
|
50 init_arg => undef, |
|
51 default => sub { $_[0]->data->{'status-text'} }, |
|
52 ); |
|
53 |
|
54 sub _data { |
|
55 my $self = shift; |
|
56 my %_data; |
|
57 my $_ = $self->response; |
|
58 while (/^(\S+):\s*(.*)$/gm) { |
|
59 $_data{lc $1} = $2; |
|
60 } |
|
61 return \%_data; |
|
62 } |
|
63 |
|
64 __PACKAGE__->meta->make_immutable; |