| 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
Condition33%1/3
not defined $request_field or $request_field eq ""
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 ""
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
not defined $value or $value eq ""
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 ""
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 53 | 10 | my $constraint = find_type_constraint( $type ); | |||||||||||||||||||||||||||
| 54 | 10 | my $err = $constraint->validate( $value ); | |||||||||||||||||||||||||||
| 55 | 10 | ▶ | if( defined $err ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||