File Coverage

blib/lib/Specio/Constraint/ObjectIsa.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::ObjectIsa;
2              
3 2     2   17 use strict;
  2         5  
  2         70  
4 2     2   12 use warnings;
  2         4  
  2         110  
5              
6             our $VERSION = '0.46';
7              
8 2     2   13 use Role::Tiny::With;
  2         4  
  2         106  
9 2     2   14 use Scalar::Util ();
  2         5  
  2         41  
10 2     2   13 use Specio::Helpers qw( perlstring );
  2         4  
  2         82  
11 2     2   13 use Specio::Library::Builtins;
  2         4  
  2         17  
12 2     2   14 use Specio::OO;
  2         4  
  2         129  
13              
14 2     2   1043 use Specio::Constraint::Role::IsaType;
  2         5  
  2         328  
15             with 'Specio::Constraint::Role::IsaType';
16              
17             {
18             my $Object = t('Object');
19 3     3   34 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, $val, perlstring( $self->class ) );
28             ( Scalar::Util::blessed( %s ) && %s->isa(%s) )
29             EOF
30             };
31              
32 3     3   103 sub _build_inline_generator {$_inline_generator}
33             }
34              
35             ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
36 3     3   8 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 inherits from a specific class
44              
45             __END__
46              
47             =pod
48              
49             =encoding UTF-8
50              
51             =head1 NAME
52              
53             Specio::Constraint::ObjectIsa - A class for constraints which require an object that inherits from a specific class
54              
55             =head1 VERSION
56              
57             version 0.46
58              
59             =head1 SYNOPSIS
60              
61             my $type = Specio::Constraint::ObjectIsa->new(...);
62             print $type->class;
63              
64             =head1 DESCRIPTION
65              
66             This is a specialized type constraint class for types which require an object
67             that inherits from a specific class.
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::ObjectIsa->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<class>. This must be a
85             single class name.
86              
87             =head2 $object_isa->class
88              
89             Returns the class name passed to the constructor.
90              
91             =head1 ROLES
92              
93             This class does the L<Specio::Constraint::Role::IsaType>,
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