File Coverage

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