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 3     3   22 use strict;
  3         6  
  3         101  
4 3     3   17 use warnings;
  3         6  
  3         150  
5              
6             our $VERSION = '0.46';
7              
8 3     3   17 use Role::Tiny::With;
  3         6  
  3         169  
9 3     3   19 use Scalar::Util ();
  3         7  
  3         67  
10 3     3   16 use Specio::Helpers qw( perlstring );
  3         6  
  3         119  
11 3     3   26 use Specio::Library::Builtins;
  3         7  
  3         25  
12 3     3   23 use Specio::OO;
  3         8  
  3         212  
13              
14 3     3   988 use Specio::Constraint::Role::DoesType;
  3         7  
  3         548  
15             with 'Specio::Constraint::Role::DoesType';
16              
17             {
18             my $Object = t('Object');
19 5     5   44 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 5     5   150 sub _build_inline_generator {$_inline_generator}
33             }
34              
35             ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
36 5     5   11 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.46
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 - 2020 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