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

filter: Statementstmt 0.0% 0 / 44 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 71 CC 7 SCAR 29.2
CC
7
Cov
0%
contact
42.0
new
6.0
BEGIN
2.0
CRAP 18.5
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 $this{$_} = eval{ YAML::XS::LoadFile "$util{conf}/$_" };
33 die "load config error:$@" if $@;
34 }qw( contact team );
35  
36 bless \%this, ref $class || $class;
37 }
38  
39 sub contact
40 {
41 my ( $this, $user, $type, $depth ) = @_;
42  
43 $depth ++;
44 return () if $depth > 5;
45 my %c;
46 if ( $user =~ /(.+):(.+)/ )
47 {
48
49 my $time = time;
50 my $who = MYDan::Oncall::Policy->new( "$oncall{data}/$1" )
51 ->set( $time - MYDan::Oncall::HOUR, $time + MYDan::Oncall::HOUR )
52 ->get( $time, $2 );
53 map{ $c{$_} ++ }$this->contact( $who->{item}, $type, $depth )
54  
55
56 }
57 elsif( $user =~ s/^@// )
58 {
59 return () unless my $user = $this->{team}{$user};
60 map{ $c{$_} ++ }map{ $this->contact( $_, $type, $depth )}@$user;
61 }
62 else
63 {
64 return () unless my $c = $this->{contact}{$user}{$type};
65 return $c;
66 }
67 return keys %c;
68 }
69  
70 1;