| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
$ad->{"countries"} and &none(sub {
$args{"country"} eq $_;
}
, @{$$ad{"countries"};})
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"};})
| |||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | 0 | ▶ | if (defined $args{limit}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | last if $args{limit} <= 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||