| 1 | package Mail::MtPolicyd::Plugin::Role::UserConfig; | ||||||||||
| 2 | |||||||||||
| 3 | 11 | ▶ | use strict; # make critic happy | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 11 | ▶ | use MooseX::Role::Parameterized; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 11 | our $VERSION = '2.01'; # VERSION | |||||||||
| 7 | # ABSTRACT: role for plugins using per user/request configuration | ||||||||||
| 8 | |||||||||||
| 9 | 11 | parameter uc_attributes => ( | |||||||||
| 10 | isa => 'ArrayRef', | ||||||||||
| 11 | required => 1, | ||||||||||
| 12 | ); | ||||||||||
| 13 | |||||||||||
| 14 | role { | ||||||||||
| 15 | 31 | ▶ | my $p = shift; | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 16 | |||||||||||
| 17 | 31 | foreach my $attribute ( @{$p->uc_attributes} ) { | |||||||||
| 18 | 63 | has 'uc_'.$attribute => ( | |||||||||
| 19 | is => 'rw', | ||||||||||
| 20 | isa => 'Maybe[Str]', | ||||||||||
| 21 | ); | ||||||||||
| 22 | } | ||||||||||
| 23 | 11 | }; | |||||||||
| 24 | |||||||||||
| 25 | sub get_uc { | ||||||||||
| 26 | 95 | ▶ | my ($self, $session, $attr) = @_; | ||||||||
|
Subroutine
get_uc: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||
| 27 | 95 | my $uc_attr = 'uc_'.$attr; | |||||||||
| 28 | |||||||||||
| 29 | 95 | ▶ | if( ! $self->can($uc_attr) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | 0 | die('there is no user config attribute '.$uc_attr.'!'); | |||||||||
| 31 | } | ||||||||||
| 32 | 95 | ▶ | if( ! defined $self->$uc_attr ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 83 | return $self->$attr; | |||||||||
| 34 | } | ||||||||||
| 35 | 12 | my $session_value = $session->{$self->$uc_attr}; | |||||||||
| 36 | 12 | ▶ | if( ! defined $session_value ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 6 | return $self->$attr; | |||||||||
| 38 | } | ||||||||||
| 39 | 6 | return $session_value; | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 11 | 1; | |||||||||
| 43 | |||||||||||
| 44 | __END__ | ||||||||||
| 45 | |||||||||||
| 46 | =pod | ||||||||||
| 47 | |||||||||||
| 48 | =encoding UTF-8 | ||||||||||
| 49 | |||||||||||
| 50 | =head1 NAME | ||||||||||
| 51 | |||||||||||
| 52 | Mail::MtPolicyd::Plugin::Role::UserConfig - role for plugins using per user/request configuration | ||||||||||
| 53 | |||||||||||
| 54 | =head1 VERSION | ||||||||||
| 55 | |||||||||||
| 56 | version 2.01 | ||||||||||
| 57 | |||||||||||
| 58 | =head1 AUTHOR | ||||||||||
| 59 | |||||||||||
| 60 | Markus Benning <ich@markusbenning.de> | ||||||||||
| 61 | |||||||||||
| 62 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 63 | |||||||||||
| 64 | This software is Copyright (c) 2014 by Markus Benning <ich@markusbenning.de>. | ||||||||||
| 65 | |||||||||||
| 66 | This is free software, licensed under: | ||||||||||
| 67 | |||||||||||
| 68 | The GNU General Public License, Version 2, June 1991 | ||||||||||
| 69 | |||||||||||
| 70 | =cut | ||||||||||