blib/lib/Gapp/Util.pm

filter: Statementstmt 69.7% 30 / 43 Branchbran 45.0% 9 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 4 / 8 Podpod 50.0% 2 / 4 totaltotal 60.0% 45 / 75 CC 11 SCAR 21.1
CC
11
Cov
62%
resolve_gapp_class_alias
20.0
add_handles
7.1
_build_alias_package_name
6.0
CRAP 8.2
« blib/lib/Gapp/Meta/Widget/Native/Trait/Form.pm ↑ Summary blib/lib/Gapp/Box.pm »
1 package Gapp::Util;
2 {
3 2 $Gapp::Util::VERSION = '0.60';
4 }
5  
6 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use MooseX::Types::Moose qw( ArrayRef HashRef );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Sub::Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10  
11  
12 2 Sub::Exporter::setup_exporter({
13 exports => [qw( resolve_gapp_trait_alias replace_entities add_handles)],
14 groups => { all => [qw( resolve_gapp_trait_alias replace_entities add_handles )] }
15 });
16  
17 # resolve custom widget trait names
18 0 ▶sub _build_alias_package_name {
Subroutine _build_alias_package_name: not called CC=2 SCAR=17.9
19 0 my ( $type, $name, $trait ) = @_;
20 0 ▶ return 'Gapp::Meta::'
Branch: 1 branch
BranchTrueFalseTotal
$trait ? : 0 0 0
21 . $type
22 . '::Custom::'
23 . ( $trait ? 'Trait::' : '' )
24 . $name;
25 }
26  
27 {
28 2 my %cache;
29  
30 0 ▶ sub resolve_gapp_class_alias {
Subroutine resolve_gapp_class_alias: not called CC=4 SCAR=30.0
Pod undocumented
31 0 my ( $type, $widget_class_name, %options ) = @_;
32  
33 0 ▶ my $cache_key = $type . q{ } . ( $options{trait} ? '-Trait' : '' );
Branch: 1 branch
BranchTrueFalseTotal
$options{'trait'} ? : 0 0 0
34 return $cache{$cache_key}{$widget_class_name}
35 0 ▶ if $cache{$cache_key}{$widget_class_name};
Branch: 1 branch
BranchTrueFalseTotal
if $cache{$cache_key}{$widget_class_name} 0 0 0
36  
37 my $possible_full_name = _build_alias_package_name(
38 $type, $widget_class_name, $options{trait}
39 0 );
40  
41 0 my $loaded_class = Class::MOP::load_first_existing_class(
42 $possible_full_name,
43 $widget_class_name
44 );
45  
46 0 ▶ return $cache{$cache_key}{$widget_class_name}
Branch: 1 branch
BranchTrueFalseTotal
$loaded_class->can('register_implementation') ? : 0 0 0
47 = $loaded_class->can('register_implementation')
48 ? $loaded_class->register_implementation
49 : $loaded_class;
50 }
51 }
52  
53  
54 2 ▶sub resolve_gapp_trait_alias {
Subroutine resolve_gapp_trait_alias: not called CC=1 SCAR=1.2
Pod documented
55 0 return resolve_gapp_class_alias( @_, trait => 1 );
56 }
57  
58 # convert entities for passing to markup properties
59 0 ▶sub replace_entities {
Subroutine replace_entities: not called CC=1 SCAR=6.9
Pod undocumented
60 0 my ( $str ) = @_;
61
62 0 $str =~ s/&/&/g;
63 0 return $str;
64 }
65  
66 # add handles
67 4 ▶sub add_handles {
Subroutine add_handles: called CC=7 SCAR=19.7
Pod documented
68 4 my ($orig, $handles ) = @_;
69
70 # if the current handles value is an array-ref
71 4 ▶ if ( is_ArrayRef $orig ) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_ArrayRef($orig)) { } 2 2 4
elsif (is_HashRef($orig)) { } 2 0 2
72
73 # and the new values are an array ref
74 2 ▶ if ( is_ArrayRef $handles ) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_ArrayRef($handles)) { } 1 1 2
elsif (is_HashRef($handles)) { } 1 0 1
75
76 # then merge the array refs
77 1 push @{ $orig }, @$handles;
78 }
79
80 # and the new values are a hash-ref
81 elsif ( is_HashRef $handles ) {
82
83 # create new hash-ref containing all handles
84 1 my %newvalue = %$handles;
85 1 map { $newvalue{$_} = $_ } @$orig;
86 1 $orig = \%newvalue;
87 }
88 }
89
90 # if the current handle value is a hash-ref
91 elsif ( is_HashRef $orig ) {
92
93 # and the new values are an array ref
94 2 ▶ if ( is_ArrayRef $handles ) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_ArrayRef($handles)) { } 1 1 2
elsif (is_HashRef($handles)) { } 1 0 1
95
96 # save new values in the hash-ref
97 1 map { $orig->{$_} = $_ } @{$handles};
98 }
99
100 # and the new values are a hash-ref
101 elsif ( is_HashRef $handles ) {
102
103 # merge the hash-refs
104 1 $orig = { %$orig, %$handles };
105 }
106 }
107 else {
108 0 $orig = $handles;
109 }
110
111 4 return $orig;
112 }
113  
114 2 1;
115  
116 __END__
« blib/lib/Gapp/Meta/Widget/Native/Trait/Form.pm ↑ Summary blib/lib/Gapp/Box.pm »