diff options
author | Florent Villard <warly@mandriva.com> | 2006-08-04 16:45:06 +0000 |
---|---|---|
committer | Florent Villard <warly@mandriva.com> | 2006-08-04 16:45:06 +0000 |
commit | 0a7ef4aa1b338a6c23dccd0db15086596f05a22a (patch) | |
tree | 620105c88261aa086535f04d1ca5fba94cb4cbbf /lib/Youri/Check/Input/Age.pm | |
parent | 1fec4f0cac5732229070c4ad2e24c01ba2bab51b (diff) | |
download | mga-youri-core-0a7ef4aa1b338a6c23dccd0db15086596f05a22a.tar mga-youri-core-0a7ef4aa1b338a6c23dccd0db15086596f05a22a.tar.gz mga-youri-core-0a7ef4aa1b338a6c23dccd0db15086596f05a22a.tar.bz2 mga-youri-core-0a7ef4aa1b338a6c23dccd0db15086596f05a22a.tar.xz mga-youri-core-0a7ef4aa1b338a6c23dccd0db15086596f05a22a.zip |
imported initial version of youri svn
Diffstat (limited to 'lib/Youri/Check/Input/Age.pm')
-rw-r--r-- | lib/Youri/Check/Input/Age.pm | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/lib/Youri/Check/Input/Age.pm b/lib/Youri/Check/Input/Age.pm new file mode 100644 index 0000000..1b80d62 --- /dev/null +++ b/lib/Youri/Check/Input/Age.pm @@ -0,0 +1,110 @@ +# $Id: Age.pm 885 2006-04-17 22:25:00Z guillomovitch $ +package Youri::Check::Input::Age; + +=head1 NAME + +Youri::Check::Input::Age - Check maximum age + +=head1 DESCRIPTION + +This plugin checks packages age, and report the ones exceeding maximum limit. + +=cut + +use warnings; +use strict; +use Carp; +use DateTime; +use DateTime::Format::Duration; +use base 'Youri::Check::Input'; + +sub columns { + return qw/ + arch + buildtime + /; +} + +sub links { + return qw//; +} + +=head2 new(%args) + +Creates and returns a new Youri::Check::Input::Age object. + +Specific parameters: + +=over + +=item max_age $age + +Maximum age allowed (default: 1 year) + +=item pattern $pattern + +Pattern used to describe age (default: %Y year) + +=back + +=cut + +sub _init { + my $self = shift; + my %options = ( + max_age => '1 year', + pattern => '%Y year', + @_ + ); + + $self->{_format} = DateTime::Format::Duration->new( + pattern => $options{pattern} + ); + + $self->{_now} = DateTime->from_epoch( + epoch => time() + ); + + $self->{_max_age} = $options{max_age}; +} + +sub run { + my ($self, $media, $resultset) = @_; + croak "Not a class method" unless ref $self; + + my $max_age_string = $media->max_age() ? + $media->max_age() : + $self->{_max_age}; + + my $max_age = $self->{_format}->parse_duration($max_age_string); + + my $check = sub { + my ($package) = @_; + + my $buildtime = DateTime->from_epoch( + epoch => $package->get_age() + ); + + my $age = $self->{_now}->subtract_datetime($buildtime); + + if (DateTime::Duration->compare($age, $max_age) > 0) { + my $date = $buildtime->strftime("%a %d %b %G"); + + $resultset->add_result($self->{_id}, $media, $package, { + arch => $package->get_arch(), + buildtime => $date + }); + } + }; + $media->traverse_headers($check); +} + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2002-2006, YOURI project + +This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. + +=cut + +1; |