API-Docker
view release on metacpan or search on metacpan
lib/API/Docker/Role/Entity/Config.pm view on Meta::CPAN
package API::Docker::Role::Entity::Config;
# ABSTRACT: Config operations, on the generated config type
our $VERSION = '0.004';
use Moo::Role;
with 'API::Docker::Role::Entity';
requires 'id';
use API::Docker::Type::Config;
use Carp qw( croak );
use MIME::Base64 qw( decode_base64 );
use Package::Stash;
use namespace::clean;
sub decoded_data {
my ($self) = @_;
my $spec = $self->spec;
return unless defined $spec;
my $data = $spec->data;
return unless defined $data;
return decode_base64($data);
}
sub version_index {
my ($self) = @_;
my $version = $self->version;
return unless defined $version;
return $version->index;
}
sub inspect {
my ($self) = @_;
return $self->client->configs->inspect($self->id);
}
sub update {
my ($self, %opts) = @_;
my $version
= exists $opts{version} ? delete $opts{version} : $self->version_index;
return $self->client->configs->update($self->id, $version, %opts);
}
sub remove {
my ($self) = @_;
return $self->client->configs->remove($self->id);
}
# --- composition -----------------------------------------------------------
#
# Here rather than in API::Docker::API::Configs, for the reason spelled out in
# API::Docker::Role::Entity::Container: loading this role is what puts the
# methods on the class.
#
# The clash check is not decoration. Moo composes a role into a class the
# class-wins way, so a generated accessor of the same name as a method here
# would silently keep its place and the method would be missing -- and the
# generated classes are written from a specification that grows fields
# without asking. None of the five names collides today; a future one says so
# on the first `use`. `version_index` is the one to watch: the class already
# declares `version`.
{
my @provided = Package::Stash->new(__PACKAGE__)->list_all_symbols('CODE');
for my $class ('API::Docker::Type::Config') {
my $fields = $class->docker_attributes;
my @clash = sort grep { $fields->{$_} } @provided;
croak __PACKAGE__ . ': ' . $class . ' declares ' . join(', ', @clash)
. ' as a daemon field; the generated accessor would win over the '
. 'method of that name and it would be missing without a word'
if @clash;
Moo::Role->apply_roles_to_package($class, __PACKAGE__);
}
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
API::Docker::Role::Entity::Config - Config operations, on the generated config type
=head1 VERSION
version 0.004
=head1 SYNOPSIS
my $docker = API::Docker->new;
my ($config) = @{ $docker->configs->list };
( run in 1.233 second using v1.01-cache-2.11-cpan-364913b4093 )