File Coverage

blib/lib/Specio/Constraint/AnyDoes.pm
Criterion Covered Total %
statement 27 27 100.0
branch n/a
condition n/a
subroutine 11 11 100.0
pod n/a
total 38 38 100.0


line stmt bran cond sub pod time code
1              
2             use strict;
3 3     3   19 use warnings;
  3         40  
  3         84  
4 3     3   15  
  3         5  
  3         120  
5             our $VERSION = '0.48';
6              
7             use Role::Tiny::With;
8 3     3   15 use Scalar::Util ();
  3         5  
  3         126  
9 3     3   221 use Specio::Helpers qw( perlstring );
  3         133  
  3         64  
10 3     3   14 use Specio::Library::Builtins;
  3         6  
  3         105  
11 3     3   357 use Specio::OO;
  3         5  
  3         21  
12 3     3   18  
  3         6  
  3         142  
13             use Specio::Constraint::Role::DoesType;
14 3     3   374 with 'Specio::Constraint::Role::DoesType';
  3         10  
  3         480  
15              
16             {
17             my $Defined = t('Defined');
18             }
19 4     4   30  
20             {
21             my $_inline_generator = sub {
22             my $self = shift;
23             my $val = shift;
24              
25             return sprintf( <<'EOF', ($val) x 8, perlstring( $self->role ) );
26             (
27             (
28             Scalar::Util::blessed(%s) || (
29             !ref(%s)
30             && defined(%s)
31             && length(%s)
32             && %s !~ /\A
33             \s*
34             -?[0-9]+(?:\.[0-9]+)?
35             (?:[Ee][\-+]?[0-9]+)?
36             \s*
37             \z/xs
38             && ref( \%s ) ne 'GLOB'
39             )
40             )
41             && %s->can('does')
42             && %s->does(%s)
43             )
44             EOF
45             };
46              
47             }
48              
49 4     4   108 ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
50             ## use critic
51              
52             __PACKAGE__->_ooify;
53 4     4   9  
54             1;
55              
56             # ABSTRACT: A class for constraints which require a class name or an object that does a specific role
57              
58              
59             =pod
60              
61             =encoding UTF-8
62              
63             =head1 NAME
64              
65             Specio::Constraint::AnyDoes - A class for constraints which require a class name or an object that does a specific role
66              
67             =head1 VERSION
68              
69             version 0.48
70              
71             =head1 SYNOPSIS
72              
73             my $type = Specio::Constraint::AnyDoes->new(...);
74             print $type->role;
75              
76             =head1 DESCRIPTION
77              
78             This is a specialized type constraint class for types which require a class
79             name or an object that does a specific role.
80              
81             =head1 API
82              
83             This class provides all of the same methods as L<Specio::Constraint::Simple>,
84             with a few differences:
85              
86             =head2 Specio::Constraint::AnyDoes->new( ... )
87              
88             The C<parent> parameter is ignored if it passed, as it is always set to the
89             C<Defined> type.
90              
91             The C<inline_generator> and C<constraint> parameters are also ignored. This
92             class provides its own default inline generator subroutine reference.
93              
94             This class overrides the C<message_generator> default if none is provided.
95              
96             Finally, this class requires an additional parameter, C<role>. This must be a
97             single role name.
98              
99             =head2 $any_isa->role
100              
101             Returns the role name passed to the constructor.
102              
103             =head1 ROLES
104              
105             This class does the L<Specio::Constraint::Role::DoesType>,
106             L<Specio::Constraint::Role::Interface>, L<Specio::Role::Inlinable>, and
107             L<MooseX::Clone> roles.
108              
109             =head1 SUPPORT
110              
111             Bugs may be submitted at L<https://github.com/houseabsolute/Specio/issues>.
112              
113             =head1 SOURCE
114              
115             The source code repository for Specio can be found at L<https://github.com/houseabsolute/Specio>.
116              
117             =head1 AUTHOR
118              
119             Dave Rolsky <autarch@urth.org>
120              
121             =head1 COPYRIGHT AND LICENSE
122              
123             This software is Copyright (c) 2012 - 2022 by Dave Rolsky.
124              
125             This is free software, licensed under:
126              
127             The Artistic License 2.0 (GPL Compatible)
128              
129             The full text of the license can be found in the
130             F<LICENSE> file included with this distribution.
131              
132             =cut