blib/lib/MYDan/Util/Contact.pm untested

filter: Statementstmt 0.0% 0 / 45 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 76 CC 8 SCAR 29.4
CC
8
Cov
0%
contact
42.0
new
12.0
BEGIN
2.0
CRAP 18.9
1 package MYDan::Util::Contact;
2 use strict;
3 use warnings;
4 use Carp;
5 use YAML::XS;
6  
7 =head1 SYNOPSIS
8  
9 use MYDan::Util::Contact;
10 my $contact = MYDan::Util::Contact->new();
11 my $email = $contact->contact( 'user1' => 'email' );
12  
13 =cut
14  
15 use MYDan::Util::OptConf;
16 use MYDan::Oncall::Policy;
17  
18  
19  
20 our ( %util, %oncall );
21 BEGIN{
22 my $opt = MYDan::Util::OptConf->load();
23 %util = $opt->dump( 'util' );
24 %oncall = $opt->dump( 'oncall' );
25 };
26  
27 sub new
28 {
29 my ( $class, %this ) = @_;
30  
31 map{
32 my $file = "$util{conf}/$_";
33 $this{$_} = eval{ YAML::XS::LoadFile -f "$file.private" ? "$file.private" : $file };
34 die "load config error:$@" if $@;
35 }qw( contact team );
36  
37 bless \%this, ref $class || $class;
38 }
39  
40 sub contact
41 {
42 my ( $this, $user, $type, $depth ) = @_;
43  
44 $depth ++;
45 return () if $depth > 5;
46 my %c;
47 if ( $user =~ /(.+):(.+)/ )
48 {
49
50 my $time = time;
51 my $who = MYDan::Oncall::Policy->new( "$oncall{data}/$1" )
52 ->set( $time - MYDan::Oncall::HOUR, $time + MYDan::Oncall::HOUR )
53 ->get( $time, $2 );
54 map{ $c{$_} ++ }$this->contact( $who->{item}, $type, $depth )
55  
56
57 }
58 elsif( $user =~ s/^@// )
59 {
60 return () unless my $user = $this->{team}{$user};
61 map{ $c{$_} ++ }map{ $this->contact( $_, $type, $depth )}@$user;
62 }
63 else
64 {
65 return () unless my $c = $this->{contact}{$user}{$type};
66 return $c;
67 }
68 return keys %c;
69 }
70  
71 1;