File Coverage

blib/lib/Acme/Mitey/Cards/Suit.pm.mite.pm
Criterion Covered Total %
statement 67 98 68.3
branch 23 62 37.1
condition 5 21 23.8
subroutine 9 13 69.2
pod 0 5 0.0
total 104 199 52.2


line stmt bran cond sub pod time code
1             {
2              
3             package Acme::Mitey::Cards::Suit;
4 5     5   30 use strict;
  5         7  
  5         124  
5 5     5   20 use warnings;
  5         10  
  5         755  
6              
7             our $USES_MITE = "Mite::Class";
8             our $MITE_SHIM = "Acme::Mitey::Cards::Mite";
9             our $MITE_VERSION = "0.007003";
10              
11             BEGIN {
12 5     5   35 require Scalar::Util;
13 5         15 *bare = \&Acme::Mitey::Cards::Mite::bare;
14 5         12 *blessed = \&Scalar::Util::blessed;
15 5         7 *carp = \&Acme::Mitey::Cards::Mite::carp;
16 5         10 *confess = \&Acme::Mitey::Cards::Mite::confess;
17 5         7 *croak = \&Acme::Mitey::Cards::Mite::croak;
18 5         9 *false = \&Acme::Mitey::Cards::Mite::false;
19 5         6 *guard = \&Acme::Mitey::Cards::Mite::guard;
20 5         10 *lazy = \&Acme::Mitey::Cards::Mite::lazy;
21 5         12 *ro = \&Acme::Mitey::Cards::Mite::ro;
22 5         10 *rw = \&Acme::Mitey::Cards::Mite::rw;
23 5         6 *rwp = \&Acme::Mitey::Cards::Mite::rwp;
24 5         2826 *true = \&Acme::Mitey::Cards::Mite::true;
25             }
26              
27             sub new {
28 12 50   12 0 37 my $class = ref( $_[0] ) ? ref(shift) : shift;
29 12   66     40 my $meta = ( $Mite::META{$class} ||= $class->__META__ );
30 12         24 my $self = bless {}, $class;
31             my $args =
32             $meta->{HAS_BUILDARGS}
33             ? $class->BUILDARGS(@_)
34 12 50       43 : { ( @_ == 1 ) ? %{ $_[0] } : @_ };
  0 50       0  
35 12         20 my $no_build = delete $args->{__no_BUILD__};
36              
37             # Attribute: name
38 12 50       32 croak "Missing key in constructor: name" unless exists $args->{"name"};
39             (
40             (
41             do {
42              
43             package Acme::Mitey::Cards::Mite;
44 12 50       29 defined( $args->{"name"} ) and do {
45             ref( \$args->{"name"} ) eq 'SCALAR'
46 12 50       65 or ref( \( my $val = $args->{"name"} ) ) eq 'SCALAR';
47             }
48             }
49             )
50 12 50 33     17 && do {
51              
52             package Acme::Mitey::Cards::Mite;
53 12         35 length( $args->{"name"} ) > 0;
54             }
55             )
56             or croak "Type check failed in constructor: %s should be %s", "name",
57             "NonEmptyStr";
58 12         44 $self->{"name"} = $args->{"name"};
59              
60             # Attribute: abbreviation
61 12 50       22 if ( exists $args->{"abbreviation"} ) {
62 0 0       0 do {
63              
64             package Acme::Mitey::Cards::Mite;
65 0 0       0 defined( $args->{"abbreviation"} ) and do {
66             ref( \$args->{"abbreviation"} ) eq 'SCALAR'
67 0 0       0 or ref( \( my $val = $args->{"abbreviation"} ) ) eq
68             'SCALAR';
69             }
70             }
71             or croak "Type check failed in constructor: %s should be %s",
72             "abbreviation", "Str";
73 0         0 $self->{"abbreviation"} = $args->{"abbreviation"};
74             }
75              
76             # Attribute: colour
77             croak "Missing key in constructor: colour"
78 12 50       22 unless exists $args->{"colour"};
79 12 50       14 do {
80              
81             package Acme::Mitey::Cards::Mite;
82 12 50       28 defined( $args->{"colour"} ) and do {
83             ref( \$args->{"colour"} ) eq 'SCALAR'
84 12 50       42 or ref( \( my $val = $args->{"colour"} ) ) eq 'SCALAR';
85             }
86             }
87             or croak "Type check failed in constructor: %s should be %s",
88             "colour", "Str";
89 12         44 $self->{"colour"} = $args->{"colour"};
90              
91             # Enforce strict constructor
92             my @unknown = grep not(/\A(?:abbreviation|colour|name)\z/),
93 12         21 keys %{$args};
  12         83  
94             @unknown
95 12 50       32 and croak(
96             "Unexpected keys in constructor: " . join( q[, ], sort @unknown ) );
97              
98             # Call BUILD methods
99 12 50 33     33 $self->BUILDALL($args) if ( !$no_build and @{ $meta->{BUILD} || [] } );
  12 50       55  
100              
101 12         169 return $self;
102             }
103              
104             sub BUILDALL {
105 0     0 0 0 my $class = ref( $_[0] );
106 0   0     0 my $meta = ( $Mite::META{$class} ||= $class->__META__ );
107 0 0       0 $_->(@_) for @{ $meta->{BUILD} || [] };
  0         0  
108             }
109              
110             sub DESTROY {
111 0     0   0 my $self = shift;
112 0   0     0 my $class = ref($self) || $self;
113 0   0     0 my $meta = ( $Mite::META{$class} ||= $class->__META__ );
114 0 0       0 my $in_global_destruction =
115             defined ${^GLOBAL_PHASE}
116             ? ${^GLOBAL_PHASE} eq 'DESTRUCT'
117             : Devel::GlobalDestruction::in_global_destruction();
118 0 0       0 for my $demolisher ( @{ $meta->{DEMOLISH} || [] } ) {
  0         0  
119 0         0 my $e = do {
120 0         0 local ( $?, $@ );
121 0         0 eval { $demolisher->( $self, $in_global_destruction ) };
  0         0  
122 0         0 $@;
123             };
124 5     5   33 no warnings 'misc'; # avoid (in cleanup) warnings
  5         9  
  5         383  
125 0 0       0 die $e if $e; # rethrow
126             }
127 0         0 return;
128             }
129              
130             sub __META__ {
131 5     5   29 no strict 'refs';
  5         9  
  5         134  
132 5     5   23 no warnings 'once';
  5         6  
  5         5062  
133 4     4   29 my $class = shift;
134 4   33     22 $class = ref($class) || $class;
135 4         17 my $linear_isa = mro::get_linear_isa($class);
136             return {
137             BUILD => [
138 4 50       6 map { ( *{$_}{CODE} ) ? ( *{$_}{CODE} ) : () }
  4         26  
  0         0  
139 4         15 map { "$_\::BUILD" } reverse @$linear_isa
140             ],
141             DEMOLISH => [
142 4 50       13 map { ( *{$_}{CODE} ) ? ( *{$_}{CODE} ) : () }
  4         57  
  0         0  
143 4         11 map { "$_\::DEMOLISH" } @$linear_isa
  4         21  
144             ],
145             HAS_BUILDARGS => $class->can('BUILDARGS'),
146             HAS_FOREIGNBUILDARGS => $class->can('FOREIGNBUILDARGS'),
147             };
148             }
149              
150             sub DOES {
151 0     0 0 0 my ( $self, $role ) = @_;
152 0         0 our %DOES;
153 0 0       0 return $DOES{$role} if exists $DOES{$role};
154 0 0       0 return 1 if $role eq __PACKAGE__;
155 0         0 return $self->SUPER::DOES($role);
156             }
157              
158             sub does {
159 0     0 0 0 shift->DOES(@_);
160             }
161              
162             my $__XS = !$ENV{MITE_PURE_PERL}
163             && eval { require Class::XSAccessor; Class::XSAccessor->VERSION("1.19") };
164              
165             # Accessors for abbreviation
166             sub abbreviation {
167             @_ > 1
168 0         0 ? croak("abbreviation is a read-only attribute of @{[ref $_[0]]}")
169             : (
170             exists( $_[0]{"abbreviation"} ) ? $_[0]{"abbreviation"} : (
171 164 100   164 0 3299 $_[0]{"abbreviation"} = do {
    50          
172 12         30 my $default_value = $_[0]->_build_abbreviation;
173 12 50       16 do {
174              
175             package Acme::Mitey::Cards::Mite;
176 12 50       33 defined($default_value) and do {
177 12 50       54 ref( \$default_value ) eq 'SCALAR'
178             or ref( \( my $val = $default_value ) ) eq
179             'SCALAR';
180             }
181             }
182             or croak( "Type check failed in default: %s should be %s",
183             "abbreviation", "Str" );
184 12         138 $default_value;
185             }
186             )
187             );
188             }
189              
190             # Accessors for colour
191             if ($__XS) {
192             Class::XSAccessor->import(
193             chained => 1,
194             "getters" => { "colour" => "colour" },
195             );
196             }
197             else {
198             *colour = sub {
199             @_ > 1
200             ? croak("colour is a read-only attribute of @{[ref $_[0]]}")
201             : $_[0]{"colour"};
202             };
203             }
204              
205             # Accessors for name
206             if ($__XS) {
207             Class::XSAccessor->import(
208             chained => 1,
209             "getters" => { "name" => "name" },
210             );
211             }
212             else {
213             *name = sub {
214             @_ > 1
215             ? croak("name is a read-only attribute of @{[ref $_[0]]}")
216             : $_[0]{"name"};
217             };
218             }
219              
220             our %SIGNATURE_FOR;
221              
222             $SIGNATURE_FOR{"clubs"} = sub {
223             my $__NEXT__ = shift;
224              
225             my ( %tmp, $tmp, @head );
226              
227             @_ == 1
228             or croak(
229             "Wrong number of parameters in signature for %s: %s, got %d",
230             "clubs", "expected exactly 1 parameters",
231             scalar(@_)
232             );
233              
234             @head = splice( @_, 0, 1 );
235              
236             # Parameter $head[0] (type: Defined)
237             ( defined( $head[0] ) )
238             or croak( "Type check failed in signature for clubs: %s should be %s",
239             "\$_[0]", "Defined" );
240              
241             return ( &$__NEXT__( @head, @_ ) );
242             };
243              
244             $SIGNATURE_FOR{"diamonds"} = sub {
245             my $__NEXT__ = shift;
246              
247             my ( %tmp, $tmp, @head );
248              
249             @_ == 1
250             or croak(
251             "Wrong number of parameters in signature for %s: %s, got %d",
252             "diamonds", "expected exactly 1 parameters",
253             scalar(@_)
254             );
255              
256             @head = splice( @_, 0, 1 );
257              
258             # Parameter $head[0] (type: Defined)
259             ( defined( $head[0] ) )
260             or
261             croak( "Type check failed in signature for diamonds: %s should be %s",
262             "\$_[0]", "Defined" );
263              
264             return ( &$__NEXT__( @head, @_ ) );
265             };
266              
267             $SIGNATURE_FOR{"hearts"} = sub {
268             my $__NEXT__ = shift;
269              
270             my ( %tmp, $tmp, @head );
271              
272             @_ == 1
273             or croak(
274             "Wrong number of parameters in signature for %s: %s, got %d",
275             "hearts", "expected exactly 1 parameters",
276             scalar(@_)
277             );
278              
279             @head = splice( @_, 0, 1 );
280              
281             # Parameter $head[0] (type: Defined)
282             ( defined( $head[0] ) )
283             or
284             croak( "Type check failed in signature for hearts: %s should be %s",
285             "\$_[0]", "Defined" );
286              
287             return ( &$__NEXT__( @head, @_ ) );
288             };
289              
290             $SIGNATURE_FOR{"spades"} = sub {
291             my $__NEXT__ = shift;
292              
293             my ( %tmp, $tmp, @head );
294              
295             @_ == 1
296             or croak(
297             "Wrong number of parameters in signature for %s: %s, got %d",
298             "spades", "expected exactly 1 parameters",
299             scalar(@_)
300             );
301              
302             @head = splice( @_, 0, 1 );
303              
304             # Parameter $head[0] (type: Defined)
305             ( defined( $head[0] ) )
306             or
307             croak( "Type check failed in signature for spades: %s should be %s",
308             "\$_[0]", "Defined" );
309              
310             return ( &$__NEXT__( @head, @_ ) );
311             };
312              
313             $SIGNATURE_FOR{"standard_suits"} = sub {
314             my $__NEXT__ = shift;
315              
316             my ( %tmp, $tmp, @head );
317              
318             @_ == 1
319             or croak(
320             "Wrong number of parameters in signature for %s: %s, got %d",
321             "standard_suits", "expected exactly 1 parameters",
322             scalar(@_)
323             );
324              
325             @head = splice( @_, 0, 1 );
326              
327             # Parameter $head[0] (type: Defined)
328             ( defined( $head[0] ) )
329             or croak(
330             "Type check failed in signature for standard_suits: %s should be %s",
331             "\$_[0]", "Defined"
332             );
333              
334             return ( &$__NEXT__( @head, @_ ) );
335             };
336              
337             1;
338             }