blib/lib/MYDan/Notify.pm untested

filter: Statementstmt 0.0% 0 / 44 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 72 CC 4 SCAR 20.8
CC
4
Cov
0%
BEGIN
20.0
new
2.0
notify
2.0
CRAP 8.0
1 package MYDan::Notify;
2 use strict;
3 use warnings;
4 use Carp;
5 use YAML::XS;
6  
7 use File::Basename;
8 use MYDan::Util::Contact;
9  
10 my ( %level, %code );
11 BEGIN{
12 my $o = MYDan::Util::OptConf->load()->dump( 'notify' );
13 %level = %{$o->{level}};
14 for my $file ( glob "$o->{code}/*" )
15 {
16 next if $file =~ /\.private$/;
17 my $name = basename $file;
18 $code{$name} = do( -f "$file.private" ? "$file.private" : $file );
19 die "notify load code $name fail"
20 unless $code{$name} && ref $code{$name} eq 'CODE';
21 }
22 };
23  
24 sub new
25 {
26 my ( $class, %this ) = @_;
27 bless \%this, ref $class || $class;
28 }
29  
30  
31 =head3 notify
32  
33 user => + { 'user1' => 2, 'user2' => 1 },
34 mesg = > + { name => 'name1', attr => 'attr1', mesg => 'mesg1', time => 'time'}
35  
36 =cut
37  
38 sub notify
39 {
40 my ( $this, %param )= @_;
41  
42 my $contact = MYDan::Util::Contact->new();
43  
44 my ( $user, $mesg ) = @param{qw( user mesg )};
45  
46 my %notify;
47  
48 for my $u ( keys %$user )
49 {
50 my $level = $user->{$u};
51 for my $t ( @{$level{$level}} )
52 {
53 map{ $notify{$t}{$_} = 1 }$contact->contact( $u => $t );
54 }
55 }
56  
57 for my $m ( keys %notify )
58 {
59 &{$code{$m}}( user => [keys %{$notify{$m}}], mesg => $mesg );
60 }
61 }
62  
63 1;