| Jifty documentation | Contained in the Jifty distribution. |
Jifty::Response - Canonical internal representation of the result of a Jifty::Action
The answer to a Jifty::Request is a Jifty::Response object.
Currently, the response object exists merely to collect the
Jifty::Result objects of each Jifty::Action that ran.
Default the status to 200.
Deprecated. Use header(NAME, VALUE)
Gets or sets the Jifty::Result of the Jifty::Action with the given MONIKER.
Returns a hash which maps moniker to its Jifty::Result
Returns the aggregate messages of all of the Jifty::Results.
Gets or sets a generalized error response. Setting an error also makes the response a failure.
Returns true if none of the results are failures and there is no error set.
Returns true if any of the results failed or there was an error set.
| Jifty documentation | Contained in the Jifty distribution. |
use warnings; use strict; package Jifty::Response;
use Any::Moose; # Monkeypatch Mouse to silence misleading warnings. See rt.cpan.org #63675. { no warnings 'redefine'; *Mouse::Meta::Class::inherit_from_foreign_class = sub { return }; } extends 'Plack::Response'; has 'error' => (is => 'rw');
sub new { my $class = shift; my $self = $class->SUPER::new(@_); $self->status(200) unless $self->status; return $self; }
sub add_header { my $self = shift; $self->header(@_); }
sub result { my $self = shift; my $moniker = shift; $self->{results}{$moniker} = shift if @_; return $self->{results}{$moniker}; }
sub results { my $self = shift; return %{$self->{results} || {}}; }
sub messages { my $self = shift; my %results = $self->results; return map {$_, $results{$_}->message} grep {defined $results{$_}->message and length $results{$_}->message} sort keys %results; }
sub success { my $self = shift; return 0 if grep {$_->failure} values %{$self->{results} || {}}; return 1; }
sub failure { my $self = shift; return not $self->success; } no Any::Moose; __PACKAGE__->meta->make_immutable(inline_constructor => 0); 1;