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