| 1 | package Mail::Decency::ContentFilter::Core::User; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use version 0.74; our $VERSION = qv( "v0.1.6" ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use mro 'c3'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use File::Temp qw/ tempfile /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | =head1 NAME | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | Mail::Decency::ContentFilter::Core::User | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | Extensions for modules requiring a user (eg command line tools ..) | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =head1 CLASS ATTRIBUTES | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =head2 cmd_user : Str | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | Command for tretreiving a user for the command line variable "%user%" | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | =cut | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 4 | has cmd_user => ( is => 'rw', isa => 'Str', predicate => 'has_cmd_user' ); | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | =head2 default_user : Str | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | User which will be used if none could be determined (if not set, the via "to" provided recipient will be used) | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =cut | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 4 | has default_user => ( is => 'rw', isa => 'Str', predicate => 'has_default_user' ); | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | =head1 METHODS | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | =head2 pre_init | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | Add check params: cmd, check, train and untrain to list of check params | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | =cut | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | before init => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 47 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 48 | 0 | ▶ | push @{ $self->{ config_params } ||=[] }, qw/ | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"config_params"} ||= []
MC/DC0%0/1
$self->{"config_params"} ||= []
$self->{"config_params"}
Truth table0%0/2
A
A= $self->{"config_params"}
| |||||||||||||||||||||||||||||
| 49 | cmd_user | ||||||||||||||||||||||||||||
| 50 | default_user | ||||||||||||||||||||||||||||
| 51 | /; | ||||||||||||||||||||||||||||
| 52 | 4 | }; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | =head2 get_user | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | Determines the user for the command line script .. eg "dspam --user %user%" | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =cut | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | ▶ | sub get_user { | ||||||||||||||||||||||||||
|
Subroutine
get_user: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 62 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | # getting hit from cache ? | ||||||||||||||||||||||||||||
| 65 | 0 | my $cache_name = $self->name. "-User-". $self->to; | |||||||||||||||||||||||||||
| 66 | # my $cached = $self->cache->get( $cache_name ); | ||||||||||||||||||||||||||||
| 67 | # return $cached if $cached; | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | my $user; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | # using command to retreive home | ||||||||||||||||||||||||||||
| 72 | 0 | ▶ | if ( $self->has_cmd_user ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 73 | 0 | $user = $self->get_user_by_cmd; | |||||||||||||||||||||||||||
| 74 | 0 | ▶ | $self->logger->debug3( "Got user '$user' from cmd" ) if $user; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | # having module fallback method ? | ||||||||||||||||||||||||||||
| 78 | elsif ( $self->can( 'get_user_fallback' ) ) { | ||||||||||||||||||||||||||||
| 79 | 0 | $user = $self->get_user_fallback; | |||||||||||||||||||||||||||
| 80 | 0 | ▶ | $self->logger->debug3( "Got user '$user' from fallback" ) if $user; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | # determine fallback user | ||||||||||||||||||||||||||||
| 84 | 0 | ▶ | $user ||= $self->has_default_user | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$user ||= $self->has_default_user ? $self->default_user : $self->to
MC/DC0%0/2
$user ||= $self->has_default_user ? $self->default_user : $self->to
$user
$self->has_default_user ? $self->default_user : $self->to
Truth table0%0/3
A ||= B
A= $userB= $self->has_default_user ? $self->default_user : $self->to
| |||||||||||||||||||||||||||||
| 85 | ? $self->default_user | ||||||||||||||||||||||||||||
| 86 | : $self->to | ||||||||||||||||||||||||||||
| 87 | ; | ||||||||||||||||||||||||||||
| 88 | 0 | $self->logger->debug3( "Got final user '$user'" ); | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | # write to cache | ||||||||||||||||||||||||||||
| 91 | 0 | $self->cache->set( $cache_name => $user ); | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | return $user; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =head2 get_user_by_cmd | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | Using the cmd_user command to determine any user/home | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =cut | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | ▶ | sub get_user_by_cmd { | ||||||||||||||||||||||||||
|
Subroutine
get_user_by_cmd: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 105 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 106 | 0 | my ( $th, $tn ) = tempfile( $self->server->temp_dir. "/file-XXXXXX", UNLINK => 1 ); | |||||||||||||||||||||||||||
| 107 | 0 | open my $cmd_fh, '|-', $self->cmd_user. "1>\"$tn\""; | |||||||||||||||||||||||||||
| 108 | 0 | print $cmd_fh $self->to; | |||||||||||||||||||||||||||
| 109 | 0 | close $cmd_fh; | |||||||||||||||||||||||||||
| 110 | 0 | reset $th; | |||||||||||||||||||||||||||
| 111 | 0 | my ( $user ) = <$th>; | |||||||||||||||||||||||||||
| 112 | 0 | chomp $user; | |||||||||||||||||||||||||||
| 113 | 0 | close $th; | |||||||||||||||||||||||||||
| 114 | 0 | ▶ | unlink( $tn ) if -f $tn; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | Ulrich Kautz <uk@fortrabbit.de> | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | Copyright (c) 2010 the L</AUTHOR> as listed above | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | =head1 LICENCSE | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | This library is free software and may be distributed under the same terms as perl itself. | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | =cut | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 4 | 1; | |||||||||||||||||||||||||||