File Coverage

blib/lib/Class/Privacy.pm
Criterion Covered Total %
statement 14 18 77.7
branch 2 4 50.0
condition 3 6 50.0
subroutine 4 5 80.0
pod n/a
total 23 33 69.7


line stmt bran cond sub pod time code
1             package Class::Privacy;
2              
3 5     5   19386 use strict;
  5         15  
  5         1174  
4              
5             require 5.006001; # Overloading %{} et alia doesn't work before this.
6              
7             our $VERSION = 0.03;
8              
9             sub import {
10 5     5   37 my $class = shift;
11 5         34 my ($caller, $file) = (caller(0))[0,1];
12 5         16 my $check = "Class::Privacy::check::$caller";
13 5 0 0 5   11314 eval <<__EOF__;
  5 100 100 0   7975  
  5     7   45  
  5         1059  
  0         0  
  0         0  
  0         0  
  0         0  
  7         1307  
  7         58  
  4         18  
  3         30  
14             sub $check {
15             my (\$caller, \$file, \$line) = (caller(0))[0,1,2];
16             if (\$caller eq "$caller" && \$file eq "$file") {
17             return \$_[0];
18             } else {
19             # Tried to use Carp::croak here but that lead into strange
20             # error where Carp::Heavy tried to stringify the object for
21             # no apparent good reason. Anyway, using die() directly
22             # is here much simpler and faster.
23             die("Cannot dereference '$caller' object at \$file line \$line.\n");
24             }
25             }
26             package $caller;
27             use overload
28             '\%{}' => \\&$check,
29             '\@{}' => \\&$check,
30             '\${}' => \\&$check,
31             '\&{}' => \\&$check; # Unlikely, but while we are at it...
32             __EOF__
33             }
34              
35             1;
36             __END__