blib/lib/Gapp/Actions/Util.pm

filter: Statementstmt 53.2% 33 / 62 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 60.0% 9 / 15 Podpod 0.0% 0 / 5 totaltotal 37.5% 42 / 112 CC 13 SCAR 29.7
CC
13
Cov
38%
perform
56.0
parse_action
20.0
action
9.9
CRAP 19.5
« blib/lib/Gapp/Meta/Widget/Native/Role/FormField.pm ↑ Summary blib/lib/Gapp/TreeView.pm »
1 package Gapp::Actions::Util;
2 {
3 1 $Gapp::Actions::Util::VERSION = '0.60';
4 }
5  
6 1 ▶use Carp qw( carp );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use List::MoreUtils qw( all any );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Scalar::Util qw( blessed reftype );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Moose::Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use Gapp::Action;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Gapp::Action::Registry;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶use Gapp::Types qw( GappAction GappCallback );
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use MooseX::Types::Moose qw( ArrayRef CodeRef Undef );
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 Moose::Exporter->setup_import_methods(
19 with_caller => [
20 qw( action ),
21 ],
22 as_is => [
23 qw( ACTION_REGISTRY perform parse_action actioncb),
24 ]
25 );
26  
27 {
28 1 my %REGISTRY;
29  
30 0 ▶ sub ACTION_REGISTRY {
Subroutine ACTION_REGISTRY: not called CC=2 SCAR=17.9
Pod undocumented
31 0 my $class = shift;
32 0 ▶ return $REGISTRY{$class} ||= Gapp::Action::Registry->new;
Condition0%0/3
$REGISTRY{$class} ||= "Gapp::Action::Registry"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$REGISTRY{$class} ||= "Gapp::Action::Registry"->new
$REGISTRY{$class} "Gapp::Action::Registry"->new
Truth table0%0/3
A ||= B
A= $REGISTRY{$class}B= "Gapp::Action::Registry"->new
ABresult
1X1
011
000
33 }
34 }
35  
36 1 ▶sub action {
Subroutine action: not called CC=3 SCAR=23.0
Pod undocumented
37
38 0 my ( $caller, $name ) = ( shift, shift );
39 0 ▶ $name = $name->name if ref $name;
Branch: 1 branch
BranchTrueFalseTotal
if ref $name 0 0 0
40
41 0 ▶ my %p = ref $_[0] eq 'HASH' ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
42
43 0 my $action = Gapp::Action->new( name => $name, %p );
44 0 ACTION_REGISTRY( $caller )->add_action( $action );
45  
46 0 return 1;
47 }
48  
49 0 ▶sub perform {
Subroutine perform: not called CC=7 SCAR=40.3
Pod undocumented
50 0 my ( $value, @args ) = @_;
51 0 ▶ return if ! defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
52
53 0 ▶ if ( ! is_GappCallback( $value ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not is_GappCallback($value)) { } 0 0 0
54 0 carp "cannot do ($value): not a valid callback";
55 }
56 else {
57 0 ▶ my ( $cb, @args ) = is_ArrayRef( $value ) ? (@$value) : ($value);
Branch: 1 branch
BranchTrueFalseTotal
is_ArrayRef($value) ? : 0 0 0
58 0 ▶ return if ! defined $cb;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cb 0 0 0
59
60 0 ▶ if ( is_GappAction( $cb ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_GappAction($cb)) { } 0 0 0
elsif (is_CodeRef($cb)) { } 0 0 0
61 0 return $cb->perform( @args );
62 }
63 elsif ( is_CodeRef( $cb ) ) {
64 0 return $cb->( @args );
65 }
66 else {
67 0 carp "cannot do ($cb): not a valid callback";
68 }
69
70 }
71 }
72  
73 0 ▶sub parse_action {
Subroutine parse_action: not called CC=4 SCAR=30.0
Pod undocumented
74 0 my ( $value ) = @_;
75
76 0 my ( $action, @args );
77
78 0 ▶ if ( is_ArrayRef( $value ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_ArrayRef($value)) { } 0 0 0
elsif (is_GappAction($value) or is_CodeRef($value)) { } 0 0 0
79 0 ( $action, @args ) = @$value;
80 }
81 ▶ elsif ( is_GappAction( $value ) || is_CodeRef( $value ) ) {
Condition0%0/3
is_GappAction($value) or is_CodeRef($value)
l!l&&r!l&&!r
000
MC/DC0%0/2
is_GappAction($value) or is_CodeRef($value)
is_GappAction($value) is_CodeRef($value)
Truth table0%0/3
A or B
A= is_GappAction($value)B= is_CodeRef($value)
ABresult
1X1
011
000
82 0 $action = $value;
83 }
84
85 0 return $action, @args;
86 }
87  
88  
89 0 ▶sub actioncb {
Subroutine actioncb: not called CC=1 SCAR=6.9
Pod undocumented
90 0 my ( $action, $w, $args ) = @_;
91 0 ▶ return sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
92 0 my ( $gtkw, @gtkargs ) = @_;
93 0 $action->perform( $w, $args, $gtkw, \@gtkargs );
94 0 };
95 }
96  
97 1 1;
« blib/lib/Gapp/Meta/Widget/Native/Role/FormField.pm ↑ Summary blib/lib/Gapp/TreeView.pm »