Acme-Mitey-Cards
view release on metacpan or search on metacpan
lib/Acme/Mitey/Cards/Suit.pm.mite.pm view on Meta::CPAN
*rw = \&Acme::Mitey::Cards::Mite::rw;
*rwp = \&Acme::Mitey::Cards::Mite::rwp;
*true = \&Acme::Mitey::Cards::Mite::true;
*unlock = \&Acme::Mitey::Cards::Mite::unlock;
}
# Gather metadata for constructor and destructor
sub __META__ {
no strict 'refs';
my $class = shift;
$class = ref($class) || $class;
my $linear_isa = mro::get_linear_isa($class);
return {
BUILD => [
map { ( *{$_}{CODE} ) ? ( *{$_}{CODE} ) : () }
map { "$_\::BUILD" } reverse @$linear_isa
],
DEMOLISH => [
map { ( *{$_}{CODE} ) ? ( *{$_}{CODE} ) : () }
map { "$_\::DEMOLISH" } @$linear_isa
],
HAS_BUILDARGS => $class->can('BUILDARGS'),
HAS_FOREIGNBUILDARGS => $class->can('FOREIGNBUILDARGS'),
};
}
# Moose-compatibility method
sub meta {
require Acme::Mitey::Cards::MOP;
Moose::Util::find_meta( ref $_[0] or $_[0] );
}
# Standard Moose/Moo-style constructor
sub new {
my $class = ref( $_[0] ) ? ref(shift) : shift;
my $meta = ( $Mite::META{$class} ||= $class->__META__ );
my $self = bless {}, $class;
my $args =
$meta->{HAS_BUILDARGS}
? $class->BUILDARGS(@_)
: { ( @_ == 1 ) ? %{ $_[0] } : @_ };
my $no_build = delete $args->{__no_BUILD__};
# Attribute name (type: NonEmptyStr)
# has declaration, file lib/Acme/Mitey/Cards/Suit.pm, line 9
croak "Missing key in constructor: name" unless exists $args->{"name"};
(
(
do {
package Acme::Mitey::Cards::Mite;
defined( $args->{"name"} ) and do {
ref( \$args->{"name"} ) eq 'SCALAR'
or ref( \( my $val = $args->{"name"} ) ) eq 'SCALAR';
}
}
)
&& do {
package Acme::Mitey::Cards::Mite;
length( $args->{"name"} ) > 0;
}
)
or croak "Type check failed in constructor: %s should be %s", "name",
"NonEmptyStr";
$self->{"name"} = $args->{"name"};
# Attribute abbreviation (type: Str)
# has declaration, file lib/Acme/Mitey/Cards/Suit.pm, line 19
if ( exists $args->{"abbreviation"} ) {
do {
package Acme::Mitey::Cards::Mite;
defined( $args->{"abbreviation"} ) and do {
ref( \$args->{"abbreviation"} ) eq 'SCALAR'
or ref( \( my $val = $args->{"abbreviation"} ) ) eq
'SCALAR';
}
}
or croak "Type check failed in constructor: %s should be %s",
"abbreviation", "Str";
$self->{"abbreviation"} = $args->{"abbreviation"};
}
# Attribute colour (type: Str)
# has declaration, file lib/Acme/Mitey/Cards/Suit.pm, line 21
croak "Missing key in constructor: colour"
unless exists $args->{"colour"};
do {
package Acme::Mitey::Cards::Mite;
defined( $args->{"colour"} ) and do {
ref( \$args->{"colour"} ) eq 'SCALAR'
or ref( \( my $val = $args->{"colour"} ) ) eq 'SCALAR';
}
}
or croak "Type check failed in constructor: %s should be %s",
"colour", "Str";
$self->{"colour"} = $args->{"colour"};
# Call BUILD methods
$self->BUILDALL($args) if ( !$no_build and @{ $meta->{BUILD} || [] } );
# Unrecognized parameters
my @unknown = grep not(/\A(?:abbreviation|colour|name)\z/),
keys %{$args};
@unknown
and croak(
"Unexpected keys in constructor: " . join( q[, ], sort @unknown ) );
return $self;
}
# Used by constructor to call BUILD methods
sub BUILDALL {
my $class = ref( $_[0] );
my $meta = ( $Mite::META{$class} ||= $class->__META__ );
$_->(@_) for @{ $meta->{BUILD} || [] };
}
# Destructor should call DEMOLISH methods
( run in 2.670 seconds using v1.01-cache-2.11-cpan-c221a9de4ec )