File Coverage

blib/lib/perl5i/0/Meta/Instance.pm
Criterion Covered Total %
statement 9 29 31.0
branch 0 8 0.0
condition 0 3 0.0
subroutine 3 8 37.5
pod 0 5 0.0
total 12 53 22.6


line stmt bran cond sub pod time code
1             package perl5i::0::Meta::Instance;
2              
3 1     1   10 use strict;
  1         3  
  1         54  
4 1     1   7 use warnings;
  1         2  
  1         65  
5              
6             require Scalar::Util;
7             require overload;
8             require Carp;
9              
10 1     1   7 use parent qw(perl5i::0::Meta);
  1         3  
  1         10  
11              
12             sub class {
13 0     0 0   return ref ${$_[0]};
  0            
14             }
15              
16             sub reftype {
17 0     0 0   return Scalar::Util::reftype(${$_[0]});
  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 0     0 0   my $code;
30              
31 0 0         if( $code = $_[0]->$has_string_overload ) {
32 0           require Taint::Util;
33 0           return Taint::Util::tainted( $code->(${$_[0]}) );
  0            
34             }
35             else {
36 0           return 0;
37             }
38              
39 0           die "Never should be reached";
40             }
41              
42              
43             sub taint {
44 0 0   0 0   if( $_[0]->$has_string_overload ) {
45 0 0         Carp::croak "Untainted overloaded objects cannot normally be made tainted" if
46             !$_[0]->is_tainted;
47 0           return 1;
48             }
49             else {
50 0           Carp::croak "Only scalars can normally be made tainted";
51             }
52              
53 0           Carp::confess "Should not be reached";
54             }
55              
56              
57             sub untaint {
58 0 0 0 0 0   if( $_[0]->$has_string_overload && $_[0]->is_tainted ) {
59 0           Carp::croak "Tainted overloaded objects cannot normally be untainted";
60             }
61             else {
62 0           return 1;
63             }
64              
65 0           Carp::confess "Should never be reached";
66             }
67              
68             1;