blib/lib/perl5i/0/Meta/Instance.pm untested

filter: Statementstmt 0.0% 0 / 44 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 79 CC 5 SCAR 15.8
CC
5
Cov
0%
taint
12.0
is_tainted
6.0
untaint
6.0
CRAP 4.9
1 package perl5i::0::Meta::Instance;
2  
3 use strict;
4 use warnings;
5  
6 require Scalar::Util;
7 require overload;
8 require Carp;
9  
10 use parent qw(perl5i::0::Meta);
11  
12 sub class {
13 return ref ${$_[0]};
14 }
15  
16 sub reftype {
17 return Scalar::Util::reftype(${$_[0]});
18 }
19  
20  
21 # Only instances can be tainted
22  
23 # Returns the code which will run when the object is used as a string
24 my $has_string_overload = sub {
25 return overload::Method(${$_[0]}, q[""]) || overload::Method(${$_[0]}, q[0+])
26 };
27  
28 sub is_tainted {
29 my $code;
30  
31 if( $code = $_[0]->$has_string_overload ) {
32 require Taint::Util;
33 return Taint::Util::tainted( $code->(${$_[0]}) );
34 }
35 else {
36 return 0;
37 }
38  
39 die "Never should be reached";
40 }
41  
42  
43 sub taint {
44 if( $_[0]->$has_string_overload ) {
45 Carp::croak "Untainted overloaded objects cannot normally be made tainted" if
46 !$_[0]->is_tainted;
47 return 1;
48 }
49 else {
50 Carp::croak "Only scalars can normally be made tainted";
51 }
52  
53 Carp::confess "Should not be reached";
54 }
55  
56  
57 sub untaint {
58 if( $_[0]->$has_string_overload && $_[0]->is_tainted ) {
59 Carp::croak "Tainted overloaded objects cannot normally be untainted";
60 }
61 else {
62 return 1;
63 }
64  
65 Carp::confess "Should never be reached";
66 }
67  
68 1;