File Coverage

blib/lib/Acme/Mitey/Cards/Card/Face.pm.mite.pm
Criterion Covered Total %
statement 78 91 85.7
branch 29 50 58.0
condition 7 18 38.8
subroutine 13 21 61.9
pod 0 3 0.0
total 127 183 69.4


line stmt bran cond sub pod time code
1             {
2              
3             package Acme::Mitey::Cards::Card::Face;
4 3     3   16 use strict;
  3         5  
  3         73  
5 3     3   13 use warnings;
  3         5  
  3         67  
6 3     3   12 no warnings qw( once void );
  3         4  
  3         310  
7              
8             our $USES_MITE = "Mite::Class";
9             our $MITE_SHIM = "Acme::Mitey::Cards::Mite";
10             our $MITE_VERSION = "0.010002";
11              
12             # Mite keywords
13             BEGIN {
14 3     3   11 my ( $SHIM, $CALLER ) =
15             ( "Acme::Mitey::Cards::Mite", "Acme::Mitey::Cards::Card::Face" );
16             (
17             *after, *around, *before, *extends, *field,
18             *has, *param, *signature_for, *with
19             )
20 3         6 = do {
21              
22             package Acme::Mitey::Cards::Mite;
23 3     3   15 no warnings 'redefine';
  3         6  
  3         590  
24             (
25 0     0   0 sub { $SHIM->HANDLE_after( $CALLER, "class", @_ ) },
26 0     0   0 sub { $SHIM->HANDLE_around( $CALLER, "class", @_ ) },
27 0     0   0 sub { $SHIM->HANDLE_before( $CALLER, "class", @_ ) },
28       3     sub { },
29 0     0   0 sub { $SHIM->HANDLE_has( $CALLER, field => @_ ) },
30 6     6   24 sub { $SHIM->HANDLE_has( $CALLER, has => @_ ) },
31 0     0   0 sub { $SHIM->HANDLE_has( $CALLER, param => @_ ) },
32 6     6   17 sub { $SHIM->HANDLE_signature_for( $CALLER, "class", @_ ) },
33 0     0   0 sub { $SHIM->HANDLE_with( $CALLER, @_ ) },
34 3         448 );
35             };
36             }
37              
38             # Mite imports
39             BEGIN {
40 3     3   17 require Scalar::Util;
41 3         8 *STRICT = \&Acme::Mitey::Cards::Mite::STRICT;
42 3         11 *bare = \&Acme::Mitey::Cards::Mite::bare;
43 3         7 *blessed = \&Scalar::Util::blessed;
44 3         4 *carp = \&Acme::Mitey::Cards::Mite::carp;
45 3         5 *confess = \&Acme::Mitey::Cards::Mite::confess;
46 3         3 *croak = \&Acme::Mitey::Cards::Mite::croak;
47 3         6 *false = \&Acme::Mitey::Cards::Mite::false;
48 3         4 *guard = \&Acme::Mitey::Cards::Mite::guard;
49 3         5 *lazy = \&Acme::Mitey::Cards::Mite::lazy;
50 3         4 *ro = \&Acme::Mitey::Cards::Mite::ro;
51 3         4 *rw = \&Acme::Mitey::Cards::Mite::rw;
52 3         5 *rwp = \&Acme::Mitey::Cards::Mite::rwp;
53 3         97 *true = \&Acme::Mitey::Cards::Mite::true;
54             }
55              
56             BEGIN {
57 3     3   525 require Acme::Mitey::Cards::Card;
58              
59 3     3   14 use mro 'c3';
  3         6  
  3         20  
60 3         7 our @ISA;
61 3         799 push @ISA, "Acme::Mitey::Cards::Card";
62             }
63              
64             # Standard Moose/Moo-style constructor
65             sub new {
66 15 50   15 0 99 my $class = ref( $_[0] ) ? ref(shift) : shift;
67 15   66     40 my $meta = ( $Mite::META{$class} ||= $class->__META__ );
68 15         28 my $self = bless {}, $class;
69             my $args =
70             $meta->{HAS_BUILDARGS}
71             ? $class->BUILDARGS(@_)
72 15 50       56 : { ( @_ == 1 ) ? %{ $_[0] } : @_ };
  0 50       0  
73 15         20 my $no_build = delete $args->{__no_BUILD__};
74              
75             # Attribute deck (type: Deck)
76             # has declaration, file lib/Acme/Mitey/Cards/Card.pm, line 9
77 15 100       29 if ( exists $args->{"deck"} ) {
78             blessed( $args->{"deck"} )
79 12 50 33     69 && $args->{"deck"}->isa("Acme::Mitey::Cards::Deck")
80             or croak "Type check failed in constructor: %s should be %s",
81             "deck", "Deck";
82 12         25 $self->{"deck"} = $args->{"deck"};
83             }
84             require Scalar::Util && Scalar::Util::weaken( $self->{"deck"} )
85 15 100 33     73 if ref $self->{"deck"};
86              
87             # Attribute reverse (type: Str)
88             # has declaration, file lib/Acme/Mitey/Cards/Card.pm, line 19
89 15 100       25 if ( exists $args->{"reverse"} ) {
90 1 50       2 do {
91              
92             package Acme::Mitey::Cards::Mite;
93 1 50       2 defined( $args->{"reverse"} ) and do {
94             ref( \$args->{"reverse"} ) eq 'SCALAR'
95 1 50       5 or ref( \( my $val = $args->{"reverse"} ) ) eq 'SCALAR';
96             }
97             }
98             or croak "Type check failed in constructor: %s should be %s",
99             "reverse", "Str";
100 1         2 $self->{"reverse"} = $args->{"reverse"};
101             }
102              
103             # Attribute suit (type: Suit)
104             # has declaration, file lib/Acme/Mitey/Cards/Card/Face.pm, line 13
105 15 50       52 croak "Missing key in constructor: suit" unless exists $args->{"suit"};
106 15         16 do {
107 15         16 my $coerced_value = do {
108 15         20 my $to_coerce = $args->{"suit"};
109             (
110             (
111             do {
112 3     3   19 use Scalar::Util ();
  3         4  
  3         2134  
113 15 100       81 Scalar::Util::blessed($to_coerce)
114             and $to_coerce->isa(q[Acme::Mitey::Cards::Suit]);
115             }
116             )
117             ) ? $to_coerce : (
118             do {
119              
120             package Acme::Mitey::Cards::Mite;
121 1 50       3 defined($to_coerce) and do {
122 1 50       5 ref( \$to_coerce ) eq 'SCALAR'
123             or ref( \( my $val = $to_coerce ) ) eq 'SCALAR';
124             }
125             }
126             )
127             ? scalar(
128 15 50       19 do {
    100          
129 1         2 local $_ = $to_coerce;
130 1         1 do {
131 1         2 my $method = lc($_);
132 1         25 'Acme::Mitey::Cards::Suit'->$method;
133             }
134             }
135             )
136             : $to_coerce;
137             };
138 15 50 33     74 blessed($coerced_value)
139             && $coerced_value->isa("Acme::Mitey::Cards::Suit")
140             or croak "Type check failed in constructor: %s should be %s",
141             "suit", "Suit";
142 15         31 $self->{"suit"} = $coerced_value;
143             };
144              
145             # Attribute face (type: Character)
146             # has declaration, file lib/Acme/Mitey/Cards/Card/Face.pm, line 20
147 15 50       28 croak "Missing key in constructor: face" unless exists $args->{"face"};
148 15 100       25 do {
149              
150             package Acme::Mitey::Cards::Mite;
151             ( defined( $args->{"face"} )
152             and !ref( $args->{"face"} )
153 15 50 33     86 and $args->{"face"} =~ m{\A(?:(?:Jack|King|Queen))\z} );
154             }
155             or croak "Type check failed in constructor: %s should be %s", "face",
156             "Character";
157 14         25 $self->{"face"} = $args->{"face"};
158              
159             # Call BUILD methods
160 14 50 33     62 $self->BUILDALL($args) if ( !$no_build and @{ $meta->{BUILD} || [] } );
  14 50       41  
161              
162             # Unrecognized parameters
163 14         17 my @unknown = grep not(/\A(?:deck|face|reverse|suit)\z/), keys %{$args};
  14         74  
164             @unknown
165 14 50       33 and croak(
166             "Unexpected keys in constructor: " . join( q[, ], sort @unknown ) );
167              
168 14         45 return $self;
169             }
170              
171             my $__XS = !$ENV{MITE_PURE_PERL}
172             && eval { require Class::XSAccessor; Class::XSAccessor->VERSION("1.19") };
173              
174             # Accessors for face
175             # has declaration, file lib/Acme/Mitey/Cards/Card/Face.pm, line 20
176             if ($__XS) {
177             Class::XSAccessor->import(
178             chained => 1,
179             "getters" => { "face" => "face" },
180             );
181             }
182             else {
183             *face = sub {
184             @_ == 1 or croak('Reader "face" usage: $self->face()');
185             $_[0]{"face"};
186             };
187             }
188              
189             # Accessors for suit
190             # has declaration, file lib/Acme/Mitey/Cards/Card/Face.pm, line 13
191             if ($__XS) {
192             Class::XSAccessor->import(
193             chained => 1,
194             "getters" => { "suit" => "suit" },
195             );
196             }
197             else {
198             *suit = sub {
199             @_ == 1 or croak('Reader "suit" usage: $self->suit()');
200             $_[0]{"suit"};
201             };
202             }
203              
204             # See UNIVERSAL
205             sub DOES {
206 0     0 0   my ( $self, $role ) = @_;
207 0           our %DOES;
208 0 0         return $DOES{$role} if exists $DOES{$role};
209 0 0         return 1 if $role eq __PACKAGE__;
210 0           return $self->SUPER::DOES($role);
211             }
212              
213             # Alias for Moose/Moo-compatibility
214             sub does {
215 0     0 0   shift->DOES(@_);
216             }
217              
218             # Method signatures
219             our %SIGNATURE_FOR;
220              
221             $SIGNATURE_FOR{"face_abbreviation"} = sub {
222             my $__NEXT__ = shift;
223              
224             my ( %tmp, $tmp, @head );
225              
226             @_ == 1
227             or
228             croak( "Wrong number of parameters in signature for %s: got %d, %s",
229             "face_abbreviation", scalar(@_), "expected exactly 1 parameters" );
230              
231             @head = splice( @_, 0, 1 );
232              
233             # Parameter invocant (type: Defined)
234             ( defined( $head[0] ) )
235             or croak(
236             "Type check failed in signature for face_abbreviation: %s should be %s",
237             "\$_[0]", "Defined"
238             );
239              
240             return ( &$__NEXT__( @head, @_ ) );
241             };
242              
243             $SIGNATURE_FOR{"to_string"} =
244             $Acme::Mitey::Cards::Card::SIGNATURE_FOR{"to_string"};
245              
246             1;
247             }