blib/lib/Attribute/Tie.pm

filter: Statementstmt 100% 47 / 47 Branchbran 87.5% 21 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 25.0% 1 / 4 totaltotal 93.0% 80 / 86 CC 13 SCAR 13.6
CC
13
Cov
96%
Tie
6.1
load
6.0
seterror
3.0
CRAP 3.9
↑ Summary
1 package Attribute::Tie;
2 #
3 # $Id: Tie.pm,v 0.2 2009/02/08 09:00:12 dankogai Exp $
4 #
5 5 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Attribute::Handlers;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 our $VERSION = sprintf "%d.%02d", q$Revision: 0.2 $ =~ /(\d+)/g;
10  
11 5 our %MOD2TIE;
12 5 our %SIGIL = qw/HASH % ARRAY @ SCALAR $/;
13 5 our $ERROR = \&error;
14  
15 3 ▶sub seterror {
Subroutine seterror: called CC=3 SCAR=11.0
Pod undocumented
16 3 my $pkg = shift;
17 $ERROR =
18 ref $_[0] eq 'CODE' ? $_[0]
19 : $_[0] ? \&error
20 1 ▶ : sub { }
Subroutine __ANON__: called CC=1 SCAR=0.0
21 3 ▶}
Branch: 2 branches
BranchTrueFalseTotal
ref $_[0] eq 'CODE' ? : 1 2 3
$_[0] ? : 1 1 2
22  
23 12 ▶sub load {
Subroutine load: called CC=6 SCAR=17.9
Pod undocumented
24 12 my ($mod2tie, $ref) = @_;
25 12 ▶ return $MOD2TIE{$mod2tie} if $MOD2TIE{$mod2tie};
Branch: 1 branch
BranchTrueFalseTotal
if $Attribute::Tie::MOD2TIE{$mod2tie} 3 9 12
26 { # Maybe you don't need to load at all
27 5 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
28 9 my $type = ref $ref;
29 return $MOD2TIE{$mod2tie} = $mod2tie
30 9 ▶ if defined &{$mod2tie . "::TIE$type" };
Branch: 1 branch
BranchTrueFalseTotal
if defined &{$mod2tie . "::TIE$type";} 0 9 9
31 return $MOD2TIE{$mod2tie} = 'Tie::'.$mod2tie
32 9 ▶ if defined &{'Tie::'. $mod2tie . "::TIE$type"};
Branch: 1 branch
BranchTrueFalseTotal
if defined &{'Tie::' . $mod2tie . "::TIE$type";} 3 6 9
33 }
34 # DB_File, et al.
35 6 eval qq{ require $mod2tie };
36 6 ▶ return $MOD2TIE{$mod2tie} = $mod2tie unless $@;
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 2 4 6
37  
38 # Anything else
39 4 eval qq{ require Tie::$mod2tie };
40 4 ▶ return $MOD2TIE{$mod2tie} = 'Tie::'.$mod2tie unless $@;
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 1 3 4
41  
42 # Report Failure and die
43 3 my ( $pkg, $file, $line ) = caller(4);
44 3 die "Neither $mod2tie nor Tie::$mod2tie is available",
45 " at $file line $line\n";
46 }
47  
48 4 ▶sub error {
Subroutine error: called CC=1 SCAR=0.0
Pod documented
49 4 my ( $ref, $mod2tie, @tiearg ) = @_;
50 4 my ( $pkg, $file, $line ) = caller(4);
51 4 my $s = $SIGIL{ ref $ref };
52 4 die "tie(", join( ", ", $s . ref $ref, qq('$mod2tie'), @tiearg ),
53 ") failed : $! at $file line $line\n";
54 }
55  
56 12 ▶sub UNIVERSAL::Tie : ATTR {
Subroutine Tie: called CC=6 SCAR=18.1
Pod undocumented
57 12 my ( $pkg, $sym, $ref, $attr, $data, $phase ) = @_;
58 12 ▶ my @tiearg = ref $data ? @$data : ($data);
Branch: 1 branch
BranchTrueFalseTotal
ref $data ? : 12 0 12
59 12 my $mod2tie = Attribute::Tie::load(shift @tiearg, $ref);
60 9 ▶ my $obj =
Branch: 3 branches
BranchTrueFalseTotal
ref $ref eq 'HASH' ? : 6 3 9
ref $ref eq 'ARRAY' ? : 2 1 3
ref $ref eq 'SCALAR' ? : 1 0 1
61 ref $ref eq 'HASH' ? tie %$ref, $mod2tie, @tiearg
62 : ref $ref eq 'ARRAY' ? tie @$ref, $mod2tie, @tiearg
63 : ref $ref eq 'SCALAR' ? tie $$ref, $mod2tie, @tiearg
64 : die "cannot tie to data type: ", ref $ref;
65 9 ▶ $Attribute::Tie::ERROR->( $ref, $mod2tie, @tiearg ) if !$obj;
Branch: 1 branch
BranchTrueFalseTotal
if not $obj 6 3 9
66 5 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
67  
68 5 1;
69 __END__
↑ Summary