API-Docker
view release on metacpan or search on metacpan
lib/API/Docker/Error/Stream.pm view on Meta::CPAN
package API::Docker::Error::Stream;
# ABSTRACT: Failure reported inside a Docker Engine progress stream
our $VERSION = '0.004';
use Moo;
# namespace::clean has to come BEFORE "use overload" here, not after it as
# everywhere else in this distribution. It sweeps the symbols `overload`
# installs -- the `("" ` slot among them -- so with the two lines in the
# house order the class ends up not overloaded at all and stringifies as
# API::Docker::Error::Stream=HASH(0x...). Nothing dies when that happens:
# every caller that only inspects $@ as a string silently starts seeing a
# reference address instead of the reason. Measured, not assumed:
# overload::Overloaded($err) is false with the lines swapped.
use namespace::clean;
use overload
'""' => sub { $_[0]->as_string },
'bool' => sub { 1 },
fallback => 1;
has message => (
is => 'ro',
required => 1,
);
has events => (
is => 'ro',
default => sub { [] },
);
has location => (
is => 'ro',
default => sub { '' },
);
sub as_string { $_[0]->message . $_[0]->location }
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
API::Docker::Error::Stream - Failure reported inside a Docker Engine progress stream
=head1 VERSION
version 0.004
=head1 SYNOPSIS
my $events = eval { $docker->images->build(context => $tar, t => 'app:v1') };
if (my $err = $@) {
# Behaves exactly like the string it replaces ...
warn "build failed: $err";
# ... and carries the whole stream that led up to the failure.
if (ref $err && $err->isa('API::Docker::Error::Stream')) {
for my $event (@{ $err->events }) {
print $event->{stream} if defined $event->{stream};
}
}
( run in 2.514 seconds using v1.01-cache-2.11-cpan-b301d465b3d )