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 3     3   21 use strict;
  3         8  
  3         144  
4 3     3   16 use warnings;
  3         5  
  3         270  
5              
6             our $VERSION = '0.53';
7              
8 3     3   18 use Role::Tiny::With;
  3         7  
  3         218  
9 3     3   17 use Scalar::Util ();
  3         6  
  3         81  
10 3     3   14 use Specio::Helpers qw( perlstring );
  3         7  
  3         155  
11 3     3   19 use Specio::Library::Builtins;
  3         6  
  3         51  
12 3     3   19 use Specio::OO;
  3         7  
  3         236  
13              
14 3     3   1747 use Specio::Constraint::Role::IsaType;
  3         9  
  3         575  
15             with 'Specio::Constraint::Role::IsaType';
16              
17             {
18             my $Object = t('Object');
19 4     4   202 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 4     4   116 sub _build_inline_generator {$_inline_generator}
33             }
34              
35             ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
36 4     4   7 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.53
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             =head1 SOURCE
101              
102             The source code repository for Specio can be found at L<https://github.com/houseabsolute/Specio>.
103              
104             =head1 AUTHOR
105              
106             Dave Rolsky <autarch@urth.org>
107              
108             =head1 COPYRIGHT AND LICENSE
109              
110             This software is Copyright (c) 2012 - 2025 by Dave Rolsky.
111              
112             This is free software, licensed under:
113              
114             The Artistic License 2.0 (GPL Compatible)
115              
116             The full text of the license can be found in the
117             F<LICENSE> file included with this distribution.
118              
119             =cut