| 1 | package Log::Saftpresse::Plugin::LimitDay; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||
| 5 | # ABSTRACT: plugin to skip messages not from today or yesterday | ||||||||||||||||||||||||||||||||
| 6 | 1 | our $VERSION = '1.5'; # VERSION | |||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 1 | extends 'Log::Saftpresse::Plugin'; | |||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Time::Piece; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Time::Seconds; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | 1 | has 'day' => ( is => 'rw', isa => 'Maybe[Str]' ); | |||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | has 'now' => ( is => 'rw', isa => 'Time::Piece', lazy => 1, | ||||||||||||||||||||||||||||||||
| 16 | 0 | ▶ | default => sub { Time::Piece->new }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 17 | 1 | ); | |||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | has 'yesterday' => ( is => 'rw', isa => 'Time::Piece', lazy => 1, | ||||||||||||||||||||||||||||||||
| 20 | default => sub { | ||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | return Time::Piece->new - ONE_DAY; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 22 | }, | ||||||||||||||||||||||||||||||||
| 23 | 1 | ); | |||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | sub is_yesterday { | ||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | my ( $self, $time ) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
is_yesterday: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | if( $self->yesterday->ymd eq $time->ymd ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 28 | 0 | return( 1 ); | |||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||
| 30 | 0 | return( 0 ); | |||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | sub is_today { | ||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | my ( $self, $time ) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
is_today: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | if( $self->now->ymd eq $time->ymd ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 36 | 0 | return( 1 ); | |||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||
| 38 | 0 | return( 0 ); | |||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | sub process { | ||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | my ( $self, $stash ) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
process: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||
| 43 | 0 | my $day = $self->day; | |||||||||||||||||||||||||||||||
| 44 | 0 | my $time = $stash->{'time'}; | |||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | if( ! defined $time ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 46 | 0 | return; | |||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | if( $day eq 'today' && ! $self->is_today($time) ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$day eq "today" and not $self->is_today($time)
MC/DC0%0/2
$day eq "today" and not $self->is_today($time)
$day eq "today"
not $self->is_today($time)
Truth table0%0/3
A and not(B)
A= $day eq "today"B= not $self->is_today($time)
| |||||||||||||||||||||||||||||||||
| 50 | 0 | return('next'); | |||||||||||||||||||||||||||||||
| 51 | ▶ | } elsif( $day eq 'yesterday' && ! $self->is_yesterday($time) ) { | |||||||||||||||||||||||||||||||
|
Condition0%0/3
$day eq "yesterday" and not $self->is_yesterday($time)
MC/DC0%0/2
$day eq "yesterday" and not $self->is_yesterday($time)
$day eq "yesterday"
not $self->is_yesterday($time)
Truth table0%0/3
A and not(B)
A= $day eq "yesterday"B= not $self->is_yesterday($time)
| |||||||||||||||||||||||||||||||||
| 52 | 0 | return('next'); | |||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | 0 | return; | |||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||
| 58 | 1 | 1; | |||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | __END__ | ||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | =pod | ||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||
| 66 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | Log::Saftpresse::Plugin::LimitDay - plugin to skip messages not from today or yesterday | ||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | =head1 VERSION | ||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | version 1.5 | ||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | Markus Benning <ich@markusbenning.de> | ||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||
| 78 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | This software is Copyright (c) 1998 by James S. Seymour, 2015 by Markus Benning. | ||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | This is free software, licensed under: | ||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||
| 84 | The GNU General Public License, Version 2, June 1991 | ||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | =cut | ||||||||||||||||||||||||||||||||