MtPolicyd/Plugin/Role/ConfigurableFields.pm

filter: Statementstmt 95.2% 40 / 42 Branchbran 75.0% 6 / 8 Conditioncond 50.0% 3 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 83.8% 57 / 68 CC 8 SCAR 13.9
CC
8
Cov
88%
get_configurable_field_value
7.6
__ANON__
2.0
BEGIN
1.0
CRAP 4.0
« MtPolicyd/ConnectionPool.pm ↑ Summary MtPolicyd/Plugin/LdapUserConfig.pm »
1 package Mail::MtPolicyd::Plugin::Role::ConfigurableFields;
2  
3 4 ▶use strict; # make critic happy
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use MooseX::Role::Parameterized;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 our $VERSION = '2.01'; # VERSION
9 # ABSTRACT: role for plugins using configurable fields
10  
11 4 parameter fields => (
12 isa => 'HashRef[HashRef]',
13 required => 1,
14 );
15  
16 role {
17 5 ▶ my $p = shift;
Subroutine __ANON__: called CC=2 SCAR=6.9
18  
19 5 foreach my $attr ( keys %{$p->fields} ) {
20 10 my $value_isa = $p->fields->{$attr}->{'value_isa'};
21 10 delete $p->fields->{$attr}->{'value_isa'};
22 has $attr.'_field' => (
23 is => 'rw',
24 isa => 'Maybe[Str]',
25 10 %{$p->fields->{$attr}},
26 );
27 method 'get_'.$attr.'_value' => sub {
28 1 ▶ my ( $self, $r ) = @_;
Subroutine get_filter_value: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
29 1 return $self->get_configurable_field_value( $r, $attr,
30 $value_isa );
31 10 };
32 }
33 4 };
34  
35 sub get_configurable_field_value {
36 11 ▶ my ( $self, $r, $name, $type ) = @_;
Subroutine get_configurable_field_value: called CC=7 SCAR=20.2
Pod undocumented
37 11 my $conf_field = $name.'_field';
38  
39 11 my $request_field = $self->$conf_field;
40 11 ▶ if( ! defined $request_field || $request_field eq '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $request_field or $request_field eq "") 0 11 11
Condition33%1/3
not defined $request_field or $request_field eq ""
l!l&&r!l&&!r
0011
MC/DC0%0/2
not defined $request_field or $request_field eq ""
not defined $request_field $request_field eq ""
Truth table33%1/3
not(A) or B
A= not defined $request_fieldB= $request_field eq ""
ABresult
1X1
011
000
41 0 $self->log( $r, 'no request field configured in '.$conf_field );
42 0 return;
43 }
44  
45 11 my $value = $r->attr( $request_field );
46 11 ▶ if( ! defined $value || $value eq '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $value or $value eq "") 1 10 11
Condition66%2/3
not defined $value or $value eq ""
l!l&&r!l&&!r
1010
MC/DC50%1/2
not defined $value or $value eq ""
not defined $value $value eq ""
Truth table66%2/3
not(A) or B
A= not defined $valueB= $value eq ""
ABresult
1X1
011
000
47 1 $self->log( $r, 'value of field '.$request_field.
48 ' not defined or empty' );
49 1 return;
50 }
51  
52 10 ▶ if( defined $type ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $type) 10 0 10
53 10 my $constraint = find_type_constraint( $type );
54 10 my $err = $constraint->validate( $value );
55 10 ▶ if( defined $err ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $err) 1 9 10
56 1 $self->log( $r, 'value of field '.$request_field.
57 ' failed validation for '.$type.': '.$err );
58 1 return;
59 }
60 }
61  
62 9 return $value;
63 }
64  
65 4 1;
66  
67 __END__
68  
69 =pod
70  
71 =encoding UTF-8
72  
73 =head1 NAME
74  
75 Mail::MtPolicyd::Plugin::Role::ConfigurableFields - role for plugins using configurable fields
76  
77 =head1 VERSION
78  
79 version 2.01
80  
81 =head1 AUTHOR
82  
83 Markus Benning <ich@markusbenning.de>
84  
85 =head1 COPYRIGHT AND LICENSE
86  
87 This software is Copyright (c) 2014 by Markus Benning <ich@markusbenning.de>.
88  
89 This is free software, licensed under:
90  
91 The GNU General Public License, Version 2, June 1991
92  
93 =cut
« MtPolicyd/ConnectionPool.pm ↑ Summary MtPolicyd/Plugin/LdapUserConfig.pm »