blib/lib/Data/Capture.pm

filter: Statementstmt 42.6% 29 / 68 Branchbran 25.0% 1 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 33.3% 11 / 33 Podpod 0.0% 0 / 14 totaltotal 34.4% 41 / 119 CC 3 SCAR 6.7
CC
3
Cov
42%
new
6.0
new
2.1
data
2.0
CRAP 2.0
↑ Summary
1 package Data::Capture;
2 1 our $VERSION = '0.27';
3 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Scalar::Util qw( refaddr blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶sub new {
Subroutine new: called CC=2 SCAR=7.6
Pod undocumented
9 1 my ( $class, @params ) = @_;
10 1 ▶ if ( @params == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@params == 1) { } 1 0 1
11 1 return bless $params[0], $class;
12 } else {
13 0 return bless { @params }, $class;
14 }
15 }
16  
17 0 ▶sub data { $_[0] }
Subroutine data: not called CC=1 SCAR=6.9
Pod undocumented
18 0 ▶sub scalar { $_[0]{invocant} } # so $$c gets invocant
Subroutine scalar: not called CC=1 SCAR=6.9
Pod undocumented
19 0 ▶sub array { $_[0]{positional} }
Subroutine array: not called CC=1 SCAR=6.9
Pod undocumented
20 0 ▶sub hash { $_[0]{named} }
Subroutine hash: not called CC=1 SCAR=6.9
Pod undocumented
21 1 ▶sub invocant { $_[0]{invocant} }
Subroutine invocant: called CC=1 SCAR=0.0
Pod undocumented
22 2 ▶sub positional { $_[0]{positional} }
Subroutine positional: called CC=1 SCAR=0.0
Pod undocumented
23 2 ▶sub named { $_[0]{named} }
Subroutine named: called CC=1 SCAR=0.0
Pod undocumented
24  
25 0 ▶sub keys { CORE::keys %{$_[0]->named} }
Subroutine keys: not called CC=1 SCAR=6.9
Pod undocumented
26 0 ▶sub values { CORE::values %{$_[0]->named} }
Subroutine values: not called CC=1 SCAR=6.9
Pod undocumented
27  
28 0 ▶sub kv { %{$_[0]->named} }
Subroutine kv: not called CC=1 SCAR=6.9
Pod undocumented
29  
30 0 ▶sub elems { scalar $_[0]->keys }
Subroutine elems: not called CC=1 SCAR=6.9
Pod undocumented
31  
32 0 ▶sub perl {
Subroutine perl: not called CC=1 SCAR=6.9
Pod undocumented
33 0 require Data::Dumper;
34 0 local $Data::Dumper::Terse = 1;
35 0 local $Data::Dumper::Sortkeys = 1;
36 0 local $Data::Dumper::Pad = ' ';
37 0 return __PACKAGE__ . "->new( " . Dumper( $_[0]->data ) . ")\n";
38 }
39  
40 0 ▶sub yaml {
Subroutine yaml: not called CC=1 SCAR=6.9
Pod undocumented
41 0 require YAML::Syck;
42 # interoperability with other YAML/Syck bindings:
43 0 $YAML::Syck::ImplicitTyping = 1;
44 0 YAML::Syck::Dump( $_[0]->data );
45 }
46  
47 package Data::Capture::Overload;
48 1 ▶use base qw(Data::Capture);
Subroutine BEGIN: called CC=1 SCAR=0.0
49  
50 1 ▶use Scalar::Util qw(blessed refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
51  
52 1 ▶use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
53 1 '@{}' => \&array,
54 '%{}' => \&hash,
55 '${}' => \&scalar,
56 fallback => 1,
57 1 );
58  
59 1 my %captures;
60  
61 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
62 0 my ( $class, @args ) = @_;
63  
64 0 ▶ my $capture = blessed($args[0]) ? $args[0] : Data::Capture->new(@args);
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($args[0]) ? : 0 0 0
65  
66 0 my $self = bless \$capture;
67  
68 0 $captures{refaddr $self} = $capture;
69  
70 0 return $self;
71 }
72  
73 0 ▶sub DESTROY { delete $captures{refaddr $_[0]} }
Subroutine DESTROY: not called CC=1 SCAR=6.9
74  
75 0 ▶sub data { $captures{refaddr $_[0]} }
Subroutine data: not called CC=1 SCAR=6.9
76 0 ▶sub scalar { $captures{refaddr $_[0]}->invocant }
Subroutine scalar: not called CC=1 SCAR=6.9
77 0 ▶sub array { $captures{refaddr $_[0]}->positional }
Subroutine array: not called CC=1 SCAR=6.9
78 0 ▶sub hash { $captures{refaddr $_[0]}->named }
Subroutine hash: not called CC=1 SCAR=6.9
79 0 ▶sub invocant { $captures{refaddr $_[0]}->invocant }
Subroutine invocant: not called CC=1 SCAR=6.9
80 0 ▶sub positional { $captures{refaddr $_[0]}->positional }
Subroutine positional: not called CC=1 SCAR=6.9
81 0 ▶sub named { $captures{refaddr $_[0]}->named }
Subroutine named: not called CC=1 SCAR=6.9
82  
83 0 ▶sub keys { CORE::keys %{$captures{refaddr $_[0]}->named} }
Subroutine keys: not called CC=1 SCAR=6.9
84 0 ▶sub values { CORE::values %{$captures{refaddr $_[0]}->named} }
Subroutine values: not called CC=1 SCAR=6.9
85  
86 0 ▶sub kv { map { ( $_, $_[0]->{$_} ) } $_[0]->keys }
Subroutine kv: not called CC=1 SCAR=6.9
87  
88  
89  
90 1 1;
91  
92 __END__
↑ Summary