Perlbal/Fields.pm

filter: Statementstmt 100% 35 / 35 Branchbran 50.0% 3 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 2 totaltotal 90.2% 46 / 51 CC 3 SCAR 4.7
CC
3
Cov
93%
__ANON__
3.0
remove
1.0
BEGIN
1.0
CRAP 1.6
« Perlbal/ManageCommand.pm ↑ Summary Perlbal/Util.pm »
1 package Perlbal::Fields;
2 23 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 23 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 23 ▶use fields;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # allow package to be called in command line
7 23 ▶__PACKAGE__->run(@ARGV) unless caller();
Branch: 1 branch
BranchTrueFalseTotal
unless caller() 0 23 23
8  
9 # should be the main method called, extra sub could be triggered from this point
10 1 ▶sub run {
Subroutine run: called CC=1 SCAR=0.0
Pod undocumented
11 1 my ( $package, @options ) = @_;
12  
13 # unactivate fields if launch in command line
14 1 $package->remove();
15  
16 1 1;
17 }
18  
19 # hash with keys and undef val for each class
20 23 my $cache_for_class = {};
21  
22 # replace fields::new method which uses Hash::Util::lock_ref_keys
23 # - it's a good idea to keep using the original fields::new during development stage
24 # - but during production we can avoid locking hash and wasting time doing this ( ~ 30 % )
25 1 ▶sub remove {
Subroutine remove: called CC=1 SCAR=0.0
Pod undocumented
26 1 my ($class) = @_;
27  
28 23 ▶ no warnings "redefine";
Subroutine BEGIN: called CC=1 SCAR=0.0
29 23 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
30 2 ▶ *fields::new = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
31 2 my $class = shift;
32 2 ▶ $class = ref $class if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 2 2
33  
34 2 ▶ if ( !defined( $cache_for_class->{$class} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $cache_for_class->{$class}) 2 0 2
35 2 my $h = {};
36 2 my @keys = keys %{ $class . "::FIELDS" };
37 2 map { $h->{$_} = undef; } @keys;
38 2 $cache_for_class->{$class} = $h;
39 }
40 2 my %h = %{ $cache_for_class->{$class} };
41  
42 2 return bless \%h, $class;
43 1 };
44 }
45  
46 23 1;
47  
« Perlbal/ManageCommand.pm ↑ Summary Perlbal/Util.pm »