File Coverage

blib/lib/Specio/TypeChecks.pm
Criterion Covered Total %
statement 23 23 100.0
branch 5 8 62.5
condition 7 18 38.8
subroutine 13 13 100.0
pod 0 8 0.0
total 48 70 68.5


line stmt bran cond sub pod time code
1             package Specio::TypeChecks;
2              
3 29     29   228 use strict;
  29         59  
  29         1018  
4 29     29   161 use warnings;
  29         55  
  29         1336  
5              
6             our $VERSION = '0.47';
7              
8 29     29   172 use Exporter qw( import );
  29         59  
  29         884  
9 29     29   156 use Specio::Helpers qw( is_class_loaded );
  29         53  
  29         1298  
10 29     29   168 use Scalar::Util qw( blessed );
  29         56  
  29         9578  
11              
12             our @EXPORT_OK = qw(
13             does_role
14             is_ArrayRef
15             is_ClassName
16             is_CodeRef
17             is_HashRef
18             is_Int
19             is_Str
20             isa_class
21             );
22              
23             sub is_ArrayRef {
24 23     23 0 470 return ref $_[0] eq 'ARRAY';
25             }
26              
27             sub is_CodeRef {
28 1041     1041 0 14994 return ref $_[0] eq 'CODE';
29             }
30              
31             sub is_HashRef {
32 15     15 0 176 return ref $_[0] eq 'HASH';
33             }
34              
35             sub is_Str {
36 6438 50 33 6438 0 111198 defined( $_[0] ) && !ref( $_[0] ) && ref( \$_[0] ) eq 'SCALAR'
      33        
37             || ref( \( my $val = $_[0] ) eq 'SCALAR' );
38             }
39              
40             sub is_Int {
41 928 50 33 928 0 15698 ( defined( $_[0] ) && !ref( $_[0] ) && ref( \$_[0] ) eq 'SCALAR'
      33        
      33        
42             || ref( \( my $val = $_[0] ) eq 'SCALAR' ) )
43             && $_[0] =~ /^[0-9]+$/;
44             }
45              
46             sub is_ClassName {
47 8     8 0 191 is_class_loaded( $_[0] );
48             }
49              
50             sub isa_class {
51 977 50   977 0 20159 blessed( $_[0] ) && $_[0]->isa( $_[1] );
52             }
53              
54             sub does_role {
55 3834 100 66 3834 0 61322 blessed( $_[0] ) && $_[0]->can('does') && $_[0]->does( $_[1] );
56             }
57              
58             1;
59              
60             # ABSTRACT: Type checks used internally for Specio classes (it's not self-bootstrapping (yet?))
61              
62             __END__
63              
64             =pod
65              
66             =encoding UTF-8
67              
68             =head1 NAME
69              
70             Specio::TypeChecks - Type checks used internally for Specio classes (it's not self-bootstrapping (yet?))
71              
72             =head1 VERSION
73              
74             version 0.47
75              
76             =head1 DESCRIPTION
77              
78             There's nothing public here.
79              
80             =for Pod::Coverage .*
81              
82             =head1 SUPPORT
83              
84             Bugs may be submitted at L<https://github.com/houseabsolute/Specio/issues>.
85              
86             I am also usually active on IRC as 'autarch' on C<irc://irc.perl.org>.
87              
88             =head1 SOURCE
89              
90             The source code repository for Specio can be found at L<https://github.com/houseabsolute/Specio>.
91              
92             =head1 AUTHOR
93              
94             Dave Rolsky <autarch@urth.org>
95              
96             =head1 COPYRIGHT AND LICENSE
97              
98             This software is Copyright (c) 2012 - 2021 by Dave Rolsky.
99              
100             This is free software, licensed under:
101              
102             The Artistic License 2.0 (GPL Compatible)
103              
104             The full text of the license can be found in the
105             F<LICENSE> file included with this distribution.
106              
107             =cut