/usr/share/perl5/Jifty/Response.pm is in libjifty-perl 1.10518+dfsg-3ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | use warnings;
use strict;
package Jifty::Response;
=head1 NAME
Jifty::Response - Canonical internal representation of the result of a L<Jifty::Action>
=head1 DESCRIPTION
The answer to a L<Jifty::Request> is a C<Jifty::Response> object.
Currently, the response object exists merely to collect the
L<Jifty::Result> objects of each L<Jifty::Action> that ran.
=cut
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');
=head2 new
Default the status to 200.
=cut
sub new {
my $class = shift;
my $self = $class->SUPER::new(@_);
$self->status(200) unless $self->status;
return $self;
}
=head2 add_header NAME VALUE
Deprecated. Use header(NAME, VALUE)
=cut
sub add_header {
my $self = shift;
$self->header(@_);
}
=head2 result MONIKER [RESULT]
Gets or sets the L<Jifty::Result> of the L<Jifty::Action> with the given
I<MONIKER>.
=cut
sub result {
my $self = shift;
my $moniker = shift;
$self->{results}{$moniker} = shift if @_;
return $self->{results}{$moniker};
}
=head2 results
Returns a hash which maps moniker to its L<Jifty::Result>
=cut
sub results {
my $self = shift;
return %{$self->{results} || {}};
}
=head2 messages
Returns the aggregate messages of all of the L<Jifty::Result>s.
=cut
sub messages {
my $self = shift;
my %results = $self->results;
return map {$_, $results{$_}->message} grep {defined $results{$_}->message and length $results{$_}->message} sort keys %results;
}
=head2 error [MESSAGE]
Gets or sets a generalized error response. Setting an error also
makes the response a L</failure>.
=head2 success
Returns true if none of the results are failures and there is no
L</error> set.
=cut
sub success {
my $self = shift;
return 0 if grep {$_->failure} values %{$self->{results} || {}};
return 1;
}
=head2 failure
Returns true if any of the results failed or there was an L</error>
set.
=cut
sub failure {
my $self = shift;
return not $self->success;
}
no Any::Moose;
__PACKAGE__->meta->make_immutable(inline_constructor => 0);
1;
|