| 1 | package Mojo::Redfish::Client::Result; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use Mojo::Base -base; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Mojo::Collection; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Mojo::Promise; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Mojo::JSON::Pointer; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 16 | ▶ | my $isa = sub { Scalar::Util::blessed($_[0]) && $_[0]->isa($_[1]) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 0 | ▶ | has client => sub { Carp::croak 'client is required' }, weak => 1; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 14 | 0 | ▶ | has data => sub { Carp::croak 'data is required' }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 2 | ▶ | sub get { | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 17 | 2 | my ($self, $path) = @_; | |||||||||||||||||||||||||||
| 18 | 2 | ▶ | return $self unless defined $path; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | 2 | my $target = Mojo::JSON::Pointer->new($self->data)->get($path); | |||||||||||||||||||||||||||
| 20 | 2 | return $self->_get($target); | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 2 | ▶ | sub get_p { | ||||||||||||||||||||||||||
|
Subroutine
get_p: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 24 | 2 | my ($self, $path) = @_; | |||||||||||||||||||||||||||
| 25 | 2 | ▶ | return $self unless defined $path; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 2 | my $target = Mojo::JSON::Pointer->new($self->data)->get($path); | |||||||||||||||||||||||||||
| 27 | 2 | return $self->_get_p($target); | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 14 | ▶ | sub value { | ||||||||||||||||||||||||||
|
Subroutine
value: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | 14 | my ($self, $path) = @_; | |||||||||||||||||||||||||||
| 32 | 14 | ▶ | return $self->data unless defined $path; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 14 | my $target = Mojo::JSON::Pointer->new($self->data)->get($path); | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 14 | ▶ | $target = Mojo::Collection->new(@$target) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | if ref $target eq 'ARRAY'; | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 14 | return $target; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub TO_JSON { shift->data } | ||||||||||||||||||||||||||
|
Subroutine
TO_JSON: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 4 | ▶ | sub _get { | ||||||||||||||||||||||||||
|
Subroutine
_get: called CC=7 SCAR=20.6
| |||||||||||||||||||||||||||||
| 45 | 4 | my ($self, $target) = @_; | |||||||||||||||||||||||||||
| 46 | 4 | ▶ | return $target | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | if $target->$isa('Mojo::Redfish::Client::Result'); | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 4 | ▶ | $target = Mojo::Collection->new(@$target) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | if ref $target eq 'ARRAY'; | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 2 | ▶ | return $target->map(sub{ $self->_get($_) }) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 53 | 4 | ▶ | if $target->$isa('Mojo::Collection'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 3 | ▶ | if (ref $target eq 'HASH') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 3 | ▶ | if (keys %$target == 1 && exists $target->{'@odata.id'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
keys %$target == 1 and exists $target->{"\@odata.id"}
MC/DC0%0/2
keys %$target == 1 and exists $target->{"\@odata.id"}
keys %$target == 1
exists $target->{"\@odata.id"}
Truth table33%1/3
A and B
A= keys %$target == 1B= exists $target->{"\@odata.id"}
| |||||||||||||||||||||||||||||
| 57 | 3 | $target = $target->{'@odata.id'}; | |||||||||||||||||||||||||||
| 58 | } else { | ||||||||||||||||||||||||||||
| 59 | 0 | return $self->_clone($target); | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 3 | return $self->client->get($target); | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 4 | ▶ | sub _get_p { | ||||||||||||||||||||||||||
|
Subroutine
_get_p: called CC=8 SCAR=22.1
| |||||||||||||||||||||||||||||
| 67 | 4 | my ($self, $target) = @_; | |||||||||||||||||||||||||||
| 68 | 4 | ▶ | return Mojo::Promise->resolve($target) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | if $target->$isa('Mojo::Redfish::Client::Result'); | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 4 | ▶ | $target = $target->to_array | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | if $target->$isa('Mojo::Collection'); | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 4 | ▶ | if (ref $target eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 1 | my %opt; | |||||||||||||||||||||||||||
| 76 | 1 | ▶ | if (my $c = $self->client->concurrency) { $opt{concurrency} = $c } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 2 | ▶ | return Mojo::Promise->map(\%opt, sub{ $self->_get_p($_) }, @$target) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 78 | 1 | ▶ | ->then(sub{ Mojo::Collection->new(map { $_->[0] } @_) }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 3 | ▶ | if (ref $target eq 'HASH') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 3 | ▶ | if (keys %$target == 1 && exists $target->{'@odata.id'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
keys %$target == 1 and exists $target->{"\@odata.id"}
MC/DC0%0/2
keys %$target == 1 and exists $target->{"\@odata.id"}
keys %$target == 1
exists $target->{"\@odata.id"}
Truth table33%1/3
A and B
A= keys %$target == 1B= exists $target->{"\@odata.id"}
| |||||||||||||||||||||||||||||
| 83 | 3 | $target = $target->{'@odata.id'}; | |||||||||||||||||||||||||||
| 84 | } else { | ||||||||||||||||||||||||||||
| 85 | 0 | return $self->_clone($target); | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 3 | return $self->client->get_p($target); | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 0 | ▶ | sub _clone { | ||||||||||||||||||||||||||
|
Subroutine
_clone: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 93 | 0 | my ($self, $data) = @_; | |||||||||||||||||||||||||||
| 94 | 0 | ▶ | $self->new( | ||||||||||||||||||||||||||
|
Condition0%0/3
$data // $self->data
MC/DC0%0/2
$data // $self->data
$data
$self->data
Truth table0%0/3
A // B
A= $dataB= $self->data
| |||||||||||||||||||||||||||||
| 95 | client => $self->client, | ||||||||||||||||||||||||||||
| 96 | data => ($data // $self->data), | ||||||||||||||||||||||||||||
| 97 | ); | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 3 | 1; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =head1 NAME | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | Mojo::Redfish::Client::Result | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | A class to get represent the result of a request from L<Mojo::Redfish::Client/get>. | ||||||||||||||||||||||||||||
| 109 | It encapsulates the returned data and facilitates walking further out in the tree by following links. | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | L<Mojo::Redfish::Client::Result> inherits all of the attributes from L<Mojo::Base> and implements the following new ones. | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | =head2 client | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | An instance of L<Mojo::Redfish::Client>, usually the one that created this object. | ||||||||||||||||||||||||||||
| 118 | Required and weakened. | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | =head2 data | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | The payload result from the Redfish request. | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =head1 METHODS | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | L<Mojo::Redfish::Client::Result> inherits all of the methods from L<Mojo::Base> and implements the following new ones. | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | =head2 get | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | $result = $result->get; | ||||||||||||||||||||||||||||
| 131 | my $deeper = $result->get('/deeper/key'); | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | Get the value of the L</data> for the given JSON Pointer, making additional requests to follow links if needed. | ||||||||||||||||||||||||||||
| 134 | Array values are upgraded to L<Mojo::Collection> objects and all (directly) contained values are fetched (if needed). | ||||||||||||||||||||||||||||
| 135 | The result is always either a result object or a collection; use L</value> to get a simple value out of the data by pointer. | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | =head2 get_p | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | Same as L</get> but returns a L<Mojo::Promise> that resolves to the result. | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | =head2 value | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | Similar to L</get> this method takes a pointer to dive into the L</data> however the result is never fetched from the Redfish server and the value is not upgraded to a results object. | ||||||||||||||||||||||||||||
| 144 | Arrays are still upgraded to L<Mojo::Collection> objects. | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | =head2 TO_JSON | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | Alias for L</data> as a getter only. | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | =over | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | =item L<Mojo::Redfish::Client> | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | =back | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||