blib/lib/Catalyst/Model/CPI.pm

filter: Statementstmt 57.8% 33 / 57 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 63.6% 7 / 11 Podpod 100% 3 / 3 totaltotal 51.1% 43 / 84 CC 8 SCAR 18.5
CC
8
Cov
49%
exists
12.0
__ANON__
11.5
get
6.0
CRAP 6.3
↑ Summary
1 package Catalyst::Model::CPI;
2 # ABSTRACT: Business::CPI models for Catalyst
3 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Module::Pluggable (
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 search_path => [ 'Business::CPI::Gateway' ],
6 except => [
7 'Business::CPI::Gateway::Base',
8 'Business::CPI::Gateway::Test',
9 ],
10 sub_name => 'available_gateways',
11 require => 1,
12 2 );
13 2 ▶use Moo::Role ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 extends 'Catalyst::Model';
16  
17 2 our $VERSION = '0.03'; # VERSION
18  
19 has _config_for_gateway => (
20 isa => 'HashRef',
21 is => 'ro',
22 0 ▶ default => sub { +{} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
23 2 traits => ['Hash'],
24 handles => {
25 _get_config_for_gateway => 'get',
26 },
27 );
28  
29 2 has _req => ( is => 'rw' );
30 2 has _log => ( is => 'rw' );
31  
32 1 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
33 1 my $orig = shift;
34 1 my $self = shift;
35  
36 1 my $args = $self->$orig(@_);
37  
38 1 $args->{_config_for_gateway} = delete $args->{gateway};
39  
40 1 return $args;
41 2 };
42  
43 1 ▶before COMPONENT => sub {
Subroutine __ANON__: called CC=4 SCAR=24.4
44 1 my ($self, $ctx) = @_;
45  
46 1 for ($self->available_gateways) {
47 0 ▶ if ($_->isa('Business::CPI::Gateway::Base') && $_->can('notify')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->isa("Business::CPI::Gateway::Base") and $_->can("notify")) 0 0 0
Condition0%0/3
$_->isa("Business::CPI::Gateway::Base") and $_->can("notify")
!ll&&!rl&&r
000
MC/DC0%0/2
$_->isa("Business::CPI::Gateway::Base") and $_->can("notify")
$_->isa("Business::CPI::Gateway::Base") $_->can("notify")
Truth table0%0/3
A and B
A= $_->isa("Business::CPI::Gateway::Base")B= $_->can("notify")
ABresult
0X0
100
111
48 0 Moo::Role->apply_roles_to_package(
49 $_, 'Business::CPI::Role::Request'
50 );
51 }
52 }
53 2 };
54  
55 1 ▶sub ACCEPT_CONTEXT {
Subroutine ACCEPT_CONTEXT: called CC=1 SCAR=0.0
Pod documented
56 1 my ($self, $ctx) = @_;
57  
58 1 $self->_req($ctx->req);
59 1 $self->_log($ctx->log);
60  
61 1 return $self;
62 }
63  
64 0 ▶sub get {
Subroutine get: not called CC=2 SCAR=17.9
Pod documented
65 0 my ($self, $name) = @_;
66  
67 0 ▶ if (!$self->exists($name)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->exists($name)) 0 0 0
68 0 local $" = ", ";
69 0 my @plugins = $self->available_gateways;
70 0 die "Can't get gateway $name. Available gateways are @plugins";
71 }
72  
73 0 my $fullname = "Business::CPI::Gateway::$name";
74  
75 0 my %args = %{ $self->_get_config_for_gateway($name) };
76 0 $args{req} = $self->_req;
77 0 $args{log} = $self->_log;
78  
79 0 return $fullname->new(%args);
80 }
81  
82 0 ▶sub exists {
Subroutine exists: not called CC=3 SCAR=24.8
Pod documented
83 0 my ($self, $name) = @_;
84  
85 0 my $fullname = "Business::CPI::Gateway::$name";
86  
87 0 for ($self->available_gateways) {
88 0 ▶ return 1 if $_ eq $fullname;
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq $fullname 0 0 0
89 }
90  
91 0 return 0;
92 }
93  
94  
95 package # hide from PAUSE
96 Business::CPI::Role::Request;
97 2 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
98  
99 2 has req => ( is => 'ro' );
100  
101 0 ▶around notify => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
102 0 my $orig = shift;
103 0 my $self = shift;
104  
105 0 ▶ if (scalar @_) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_) 0 0 0
106 0 die "You are using Business::CPI from Catalyst.\n" .
107 "You don't have to pass the request!\n";
108 }
109  
110 0 return $self->$orig($self->req);
111 2 };
112  
113 2 1;
114  
115 __END__
↑ Summary