lib/Mail/Decency/Core/Meta.pm

filter: Statementstmt 50.8% 30 / 59 Branchbran 4.5% 1 / 22 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 63.6% 7 / 11 Podpod 50.0% 2 / 4 totaltotal 39.6% 40 / 101 CC 14 SCAR 33.8
CC
14
Cov
37%
parse_config
72.0
_init_config
20.0
BUILD
12.0
CRAP 29.3
« lib/Mail/Decency/LogParser/GeoSource.pm ↑ Summary lib/Mail/Decency/ContentFilter/CRM114.pm »
1 package Mail::Decency::Core::Meta;
2  
3 24 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 24 ▶use version 0.74; our $VERSION = qv( "v0.1.4" );
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 24 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 24 ▶use Scalar::Util qw/ weaken blessed /;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 24 ▶use YAML qw/ LoadFile /;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 24 ▶use File::Basename qw/ dirname /;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 =head1 NAME
13  
14 Mail::Decency::Core::Meta
15  
16 =head1 DESCRIPTION
17  
18 Meta base class for most deceny modules.
19  
20  
21 =head1 CLASS ATTRIBUTES
22  
23 See L<Mail::Decency::Policy::Core>
24  
25 =cut
26  
27 24 has config => ( is => 'rw', trigger => \&_init_config , predicate => 'has_config' );
28 24 has config_dir => ( is => 'rw', isa => 'Str', predicate => 'has_config_dir' );
29 24 has cache => ( is => 'ro', isa => 'Mail::Decency::Helper::Cache', weak_ref => 1 );
30 24 has database => ( is => 'ro', isa => 'Mail::Decency::Helper::Database' );
31 24 has logger => ( is => 'ro', isa => 'Mail::Decency::Helper::Logger' );
32 24 has name => ( is => 'rw', isa => 'Str' );
33  
34 24 __PACKAGE__->meta->make_immutable;
35  
36 =head1 METHODS
37  
38  
39 =head1 BUILD
40  
41 Constructor chain
42  
43 =cut
44  
45 0 ▶sub BUILD {
Subroutine BUILD: not called CC=3 SCAR=24.8
Pod undocumented
46 0 my ( $self ) = @_;
47
48 # init policy
49 0 ▶ unless ( $self->name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->name) 0 0 0
50 0 ( my $class = ref( $self ) ) =~ s/^.*:://;
51 0 $self->name( $class );
52 }
53
54 # parse config
55 0 $self->parse_config();
56
57 # call init ..
58 0 $self->init();
59
60 # cleanup, check and such after init
61 0 ▶ $self->after_init() if $self->can( 'after_init' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->can("after_init") 0 0 0
62
63 # Here we are!
64 0 $self->logger->info( "inited" );
65
66
67 }
68  
69  
70 =head1 DEMOLISH
71  
72 Destructor chaing
73  
74 =cut
75  
76 20 ▶sub DEMOLISH {
Subroutine DEMOLISH: called CC=2 SCAR=7.1
Pod undocumented
77 20 my ( $self ) = @_;
78 20 ▶ $self->demolish() if $self->can( 'demolish' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->can("demolish") 0 20 20
79 20 $self->logger->debug0( "Stopped ". $self->name );
80 }
81  
82  
83 =head2 init
84  
85 Init class for the server
86  
87 =cut
88  
89 0 ▶sub init {
Subroutine init: not called CC=1 SCAR=6.9
Pod documented
90 0 die "Init method has to be overwritten by module ". ( ref( shift ) ). "\n";
91 }
92  
93  
94 =head2 parse_config
95  
96 Read config file , read includes ..
97  
98 =cut
99  
100 0 ▶sub parse_config {
Subroutine parse_config: not called CC=8 SCAR=42.8
Pod documented
101 0 my ( $self ) = @_;
102
103 # parse config -> find all "includes"
104 0 ▶ if ( defined $self->config->{ include } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->config->{"include"}) 0 0 0
105 my @includes = ref( $self->config->{ include } )
106 0 ? @{ $self->config->{ include } }
107 : ( $self->config->{ include } )
108 0 ▶ ;
Branch: 1 branch
BranchTrueFalseTotal
ref $self->config->{'include'} ? : 0 0 0
109
110 0 my %add = ();
111 0 foreach my $include( @includes ) {
112 0 ▶ my $path = ! -f $include && $self->has_config_dir
Branch: 1 branch
BranchTrueFalseTotal
!(-f $include) && $self->has_config_dir ? : 0 0 0
Condition0%0/3
not -f $include and $self->has_config_dir
!ll&&!rl&&r
000
MC/DC0%0/2
not -f $include and $self->has_config_dir
not -f $include $self->has_config_dir
Truth table0%0/3
not(A) and B
A= not -f $includeB= $self->has_config_dir
ABresult
0X0
100
111
113 ? $self->config_dir . "/$include"
114 : $include
115 ;
116 0 ▶ die "Cannot include config file '$path': does not exist or not readable (". (
Branch: 2 branches
BranchTrueFalseTotal
unless -f $path 0 0 0
$self->has_config_dir ? : 0 0 0
117 $self->has_config_dir
118 ? "config_dir: ". $self->config_dir
119 : "no config_dir"
120 ). ")\n"
121 unless -f $path;
122 0 %add = ( %add, %{ LoadFile( $path ) } );
123 }
124
125 # merge by replace
126 0 $self->config( { %{ $self->config }, %add } );
127 }
128 }
129  
130  
131 =head1 PRIVATE METHODS
132  
133 =head2 _init_config
134  
135 =cut
136  
137 0 ▶sub _init_config {
Subroutine _init_config: not called CC=4 SCAR=30.0
138 0 my ( $self, $config_ref ) = @_;
139 0 ▶ unless ( ref( $self->config ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $self->config) 0 0 0
140 0 ▶ die "Require hashref or path to file for config, got '". $self->config. "'\n"
Branch: 1 branch
BranchTrueFalseTotal
unless -f $config_ref 0 0 0
141 unless -f $config_ref;
142
143 # extract dir
144 0 ▶ unless ( $self->has_config_dir ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->has_config_dir) 0 0 0
145 0 my $config_dir = dirname( $config_ref );
146 0 $self->config_dir( $config_dir );
147 }
148
149 # load file from yaml
150 0 $self->config( LoadFile( $config_ref ) );
151 }
152
153 0 return;
154 }
155  
156  
157 =head1 AUTHOR
158  
159 Ulrich Kautz <uk@fortrabbit.de>
160  
161 =head1 COPYRIGHT
162  
163 Copyright (c) 2010 the L</AUTHOR> as listed above
164  
165 =head1 LICENCSE
166  
167 This library is free software and may be distributed under the same terms as perl itself.
168  
169 =cut
170  
171  
172  
173  
174 24 1;
« lib/Mail/Decency/LogParser/GeoSource.pm ↑ Summary lib/Mail/Decency/ContentFilter/CRM114.pm »