API-Docker
view release on metacpan or search on metacpan
lib/API/Docker/Role/Entity/Secret.pm view on Meta::CPAN
package API::Docker::Role::Entity::Secret;
# ABSTRACT: Secret operations, on the generated secret type
our $VERSION = '0.004';
use Moo::Role;
with 'API::Docker::Role::Entity';
requires 'id';
use API::Docker::Type::Secret;
use Carp qw( croak );
use Package::Stash;
use namespace::clean;
sub version_index {
my ($self) = @_;
my $version = $self->version;
return unless defined $version;
return $version->index;
}
sub inspect {
my ($self) = @_;
return $self->client->secrets->inspect($self->id);
}
sub update {
my ($self, %opts) = @_;
my $version
= exists $opts{version} ? delete $opts{version} : $self->version_index;
return $self->client->secrets->update($self->id, $version, %opts);
}
sub remove {
my ($self) = @_;
return $self->client->secrets->remove($self->id);
}
# --- composition -----------------------------------------------------------
#
# Here rather than in API::Docker::API::Secrets, 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 four 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::Secret') {
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::Secret - Secret operations, on the generated secret type
=head1 VERSION
version 0.004
=head1 SYNOPSIS
my $docker = API::Docker->new;
my ($secret) = @{ $docker->secrets->list };
( run in 0.813 second using v1.01-cache-2.11-cpan-364913b4093 )