Queue/Entry.pm

filter: Statementstmt 86.6% 13 / 15 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 90.0% 18 / 20 CC 1 SCAR 0.6
CC
1
Cov
87%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Queue.pm ↑ Summary Handler/Initialise.pm »
1 package PkgForge::Queue::Entry; # -*-perl-*-
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # $Id: Entry.pm.in 14566 2010-11-23 14:53:41Z squinney@INF.ED.AC.UK $
6 # $Source:$
7 # $Revision: 14566 $
8 # $HeadURL: https://svn.lcfg.org/svn/source/tags/PkgForge-Server/PkgForge_Server_1_1_10/lib/PkgForge/Queue/Entry.pm.in $
9 # $Date: 2010-11-23 14:53:41 +0000 (Tue, 23 Nov 2010) $
10  
11 our $VERSION = '1.1.10';
12  
13 2 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use File::stat ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 0 ▶use PkgForge::Utils ();
Subroutine BEGIN: called CC=1 SCAR=2.6
16  
17 use overload q{""} => sub { shift->stringify };
18  
19 use Moose;
20 use PkgForge::Types qw(AbsolutePathDirectory);
21 use MooseX::Types::Moose qw(Int Str);
22  
23 has 'path' => (
24 is => 'ro',
25 isa => AbsolutePathDirectory,
26 required => 1,
27 );
28  
29 has 'id' => (
30 is => 'ro',
31 isa => Str,
32 );
33  
34 has 'owner' => (
35 is => 'ro',
36 isa => Int,
37 );
38  
39 has 'timestamp' => (
40 is => 'ro',
41 isa => Int,
42 );
43  
44 sub stringify {
45 my ($self) = @_;
46 return $self->path;
47 }
48  
49 sub scrub {
50 my ( $self, $options ) = @_;
51  
52 PkgForge::Utils::remove_tree( $self->path, $options );
53  
54 undef $self;
55  
56 return;
57 }
58  
59 sub pretty_timestamp {
60 my ($self) = @_;
61  
62 return scalar localtime($self->timestamp)
63 }
64  
65 sub overdue {
66 my ( $self, $timeout ) = @_;
67  
68 my $now = time;
69 return ( ($now - $timeout) > $self->timestamp );
70 }
71  
72 around 'BUILDARGS' => sub {
73 my ( $orig, $class, @args ) = @_;
74  
75 my %args;
76 if ( scalar @args == 1 ) {
77 if ( defined $args[0] && ref $args[0] eq 'HASH' ) {
78 %args = %{$args[0]};
79 }
80 elsif ( defined $args[0] && !ref $args[0] ) {
81 $args{path} = $args[0];
82 }
83 else {
84 $class->throw_error( "Single parameters to new() must be a directory path or a HASH ref", data => $_[0] );
85 }
86 }
87 else {
88 %args = @args;
89 }
90  
91 my $path = $args{path};
92 if ( defined $path && -e $path ) {
93 $args{id} = (File::Spec->splitdir($path))[-1];
94  
95 my $info = File::stat::stat($path);
96 $args{owner} = $info->uid;
97 $args{timestamp} = $info->ctime;
98 }
99  
100 return $class->$orig(%args);
101 };
102  
103  
104 no Moose;
105 __PACKAGE__->meta->make_immutable;
106 1;
107 __END__
« Queue.pm ↑ Summary Handler/Initialise.pm »