BuildCommand/Builder.pm untested

filter: Statementstmt 0.0% 0 / 94 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 16 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 129 CC 6 SCAR 18.2
CC
6
Cov
0%
run
20.0
build_name
6.0
register_info
6.0
CRAP 6.2
1 package PkgForge::BuildCommand::Builder; # -*-perl-*-
2 use strict;
3 use warnings;
4  
5 # $Id: Queue.pm.in 13577 2010-08-26 08:34:57Z squinney@INF.ED.AC.UK $
6 # $Source:$
7 # $Revision: 13577 $
8 # $HeadURL: https://svn.lcfg.org/svn/source/trunk/PkgForge/lib/PkgForge/Queue.pm.in $
9 # $Date: 2010-08-26 09:34:57 +0100 (Thu, 26 Aug 2010) $
10  
11 our $VERSION = '1.1.10';
12  
13 use English qw(-no_match_vars);
14 use File::Path ();
15 use File::Spec ();
16 use File::Temp ();
17 use PkgForge::SourceUtils ();
18  
19 use Moose::Role;
20 use Moose::Util::TypeConstraints;
21 use MooseX::Types::Moose qw(Bool Int Str);
22 use Readonly;
23  
24 with 'PkgForge::BuildCommand' => { -excludes => [ 'build_name' ] };
25  
26 requires 'build';
27  
28 enum 'PkgForgeErrorPolicy' => [qw/immediate retry/];
29  
30 Readonly my %SOURCE_TYPES =>
31 map { $_ => 1 } PkgForge::SourceUtils::list_source_types();
32  
33 subtype 'PkgForgeSourceType'
34 => as Str,
35 => where { exists $SOURCE_TYPES{$_} };
36  
37 subtype 'PkgForgeSourceTypeList'
38 => as 'ArrayRef[PkgForgeSourceType]';
39  
40 coerce 'PkgForgeSourceTypeList'
41 => from Str
42 => via { [$_] };
43  
44 has 'platform' => (
45 is => 'ro',
46 isa => Str,
47 required => 1,
48 documentation => 'The platform to build on',
49 );
50  
51 has 'architecture' => (
52 is => 'ro',
53 isa => Str,
54 required => 0,
55 predicate => 'has_architecture',
56 documentation => 'The architecture to build on',
57 );
58  
59 has 'timeout' => (
60 is => 'ro',
61 isa => Int,
62 default => 600, # 10 minutes
63 documentation => 'Time after which a build job should be killed',
64 );
65  
66 has 'accepts' => (
67 traits => ['Array'],
68 is => 'ro',
69 isa => 'PkgForgeSourceTypeList',
70 required => 1,
71 coerce => 1,
72 handles => {
73 list_acceptable_types => 'elements',
74 },
75 documentation => 'The type of source packages accepted by the builder',
76 );
77  
78 has 'error_policy' => (
79 is => 'ro',
80 isa => 'PkgForgeErrorPolicy',
81 default => 'retry',
82 documentation => 'Response type on package build failure',
83 );
84  
85 has 'debug' => (
86 is => 'rw',
87 isa => Bool,
88 default => 0,
89 documentation => 'Turn on the printing of debug statements',
90 );
91  
92 subtype 'FileTempDir' => as class_type('File::Temp::Dir');
93  
94 has 'tmpdir' => (
95 is => 'ro',
96 isa => 'Str|FileTempDir',
97 required => 1,
98 default => sub {
99 return File::Temp->newdir( 'pkgforge-XXXXX',
100 TMPDIR => 1,
101 CLEANUP => 1 );
102 },
103 documentation => 'Temporary directory'
104 );
105  
106 no Moose::Role;
107  
108 sub build_name {
109 my ($self) = @_;
110  
111 my $name;
112 if ( $self->has_architecture ) {
113 $name = join q{-}, $self->platform, $self->architecture;
114 } else {
115 $name = $self->platform;
116 }
117  
118 return $name;
119 }
120  
121 sub filter_sources {
122 my ( $self, $job ) = @_;
123  
124 my @sources;
125 for my $type ($self->list_acceptable_types) {
126 my @matches = $job->filter_packages( sub { $_->type eq $type } );
127 push @sources, @matches;
128 }
129  
130 return @sources;
131 }
132  
133 sub register_info {
134 my ( $self, $job, $buildinfo ) = @_;
135  
136 # Add the builder information to the buildinfo object
137  
138 $buildinfo->platform($self->platform);
139 if ( $self->has_architecture ) {
140 $buildinfo->architecture($self->architecture);
141 }
142  
143 return
144 }
145  
146 sub run {
147 my ( $self, $job, $buildinfo, $buildlog ) = @_;
148  
149 my $logger = $buildlog->logger;
150  
151 $self->register_info( $job, $buildinfo );
152  
153 my @sources = $self->filter_sources($job);
154 if ( scalar @sources == 0 ) {
155 return;
156 }
157  
158 $buildinfo->sources(\@sources);
159  
160 my $run_result = eval { $self->build( $job, $buildinfo, $buildlog ) };
161 if ( !$run_result || $EVAL_ERROR ) {
162 if ($EVAL_ERROR) {
163 die $EVAL_ERROR; # rethrow
164 } else {
165 return 0;
166 }
167 }
168  
169 return 1;
170 }
171  
172 1;
173 __END__