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