AdServer/Database/YAML.pm

filter: Statementstmt 39.3% 24 / 61 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 58.3% 7 / 12 Podpod 0.0% 0 / 3 totaltotal 31.3% 31 / 99 CC 13 SCAR 34.4
CC
13
Cov
29%
get_ads
72.0
load
30.0
__ANON__
6.0
CRAP 31.2
↑ Summary AdServer/Database.pm »
1 package WWW::AdServer::Database::YAML;
2 {
3 1 $WWW::AdServer::Database::YAML::VERSION = '1.01';
4 }
5 1 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use YAML ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Data::Dumper qw(Dumper);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use List::Util qw(shuffle);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use List::MoreUtils qw(none);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Time::Local qw(timelocal);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 has data => (
15 is => 'rw',
16 0 ▶ isa => sub { die "$_[0] is not a refernce to a hash" unless ref $_[0] eq 'HASH' },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] eq "HASH" 0 0 0
17 1 );
18  
19 0 ▶sub load {
Subroutine load: not called CC=5 SCAR=34.0
Pod undocumented
20 0 my ($self, $path) = @_;
21 0 my $data = YAML::LoadFile($path);
22  
23 # TODO some tool to return the entries where the dead-line passed
24 0 my @valid_ads;
25 0 my $now = time;
26 0 foreach my $ad (@{ $data->{ads} }) {
27 0 ▶ if ($ad->{end_date}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ad->{"end_date"}) 0 0 0
28 0 my ($year, $month, $day) = split /-/, $ad->{end_date};
29 0 eval {
30 0 $ad->{end_date} = timelocal(59, 59, 23, $day, $month-1, $year-1900);
31 };
32 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
33 #print STDERR "$ad->{text}\n";
34 #print STDERR "$ad->{end_date}\n";
35 #print STDERR "$@\n";
36 0 $ad->{end_date} = 0;
37 }
38 0 ▶ next if $ad->{end_date} < $now;
Branch: 1 branch
BranchTrueFalseTotal
if $ad->{"end_date"} < $now 0 0 0
39 }
40 0 push @valid_ads, $ad;
41 }
42 0 $data->{ads} = \@valid_ads;
43 0 $self->data( $data );
44  
45 0 return;
46 }
47  
48 0 ▶sub count_ads {
Subroutine count_ads: not called CC=1 SCAR=6.9
Pod undocumented
49 0 my ($self) = @_;
50 0 return scalar @{ $self->data->{ads} };
51 }
52  
53 0 ▶sub get_ads {
Subroutine get_ads: not called CC=8 SCAR=42.8
Pod undocumented
54 0 my ($self, %args) = @_;
55 0 my @ads;
56 0 my @all_ads = @{ $self->data->{ads} };
57 0 ▶ if ($args{shuffle}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"shuffle"}) 0 0 0
58 0 @all_ads = shuffle @all_ads;
59 }
60 0 for my $ad (@all_ads) {
61 #warn Dumper $ad;
62 0 ▶ if ($args{country}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"country"}) 0 0 0
63 0 ▶ next if $ad->{countries} and none {$args{country} eq $_} @{ $ad->{countries} };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if $ad->{"countries"} and &none(sub { $args{"country"} eq $_; } , @{$$ad{"countries"};}) 0 0 0
Condition0%0/3
$ad->{"countries"} and &none(sub { $args{"country"} eq $_; } , @{$$ad{"countries"};})
!ll&&!rl&&r
000
MC/DC0%0/2
$ad->{"countries"} and &none(sub { $args{"country"} eq $_; } , @{$$ad{"countries"};})
$ad->{"countries"} &none(sub { $args{"country"} eq $_; } , @{$$ad{"countries"};})
Truth table0%0/3
A and B
A= $ad->{"countries"}B= &none(sub { $args{"country"} eq $_; } , @{$$ad{"countries"};})
ABresult
0X0
100
111
64 }
65 0 ▶ if (defined $args{limit}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"limit"}) 0 0 0
66 0 ▶ last if $args{limit} <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $args{"limit"} <= 0 0 0 0
67 0 $args{limit}--;
68 }
69 0 push @ads, $ad;
70 }
71  
72 0 return \@ads;
73 }
74  
75  
76 1 1;
77  
78 __END__
↑ Summary AdServer/Database.pm »