This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update Test::Harness to 3.44
[perl5.git] / cpan / Test-Harness / lib / TAP / Parser / Scheduler / Job.pm
CommitLineData
f7c69158
NC
1package TAP::Parser::Scheduler::Job;
2
3use strict;
befb5359 4use warnings;
f7c69158
NC
5use Carp;
6
7=head1 NAME
8
9TAP::Parser::Scheduler::Job - A single testing job.
10
11=head1 VERSION
12
34b62aa6 13Version 3.44
f7c69158
NC
14
15=cut
16
34b62aa6 17our $VERSION = '3.44';
f7c69158
NC
18
19=head1 SYNOPSIS
20
21 use TAP::Parser::Scheduler::Job;
22
23=head1 DESCRIPTION
24
25Represents a single test 'job'.
26
27=head1 METHODS
28
29=head2 Class Methods
30
31=head3 C<new>
32
33 my $job = TAP::Parser::Scheduler::Job->new(
dbd04185 34 $filename, $description
f7c69158
NC
35 );
36
dbd04185
NC
37Given the filename and description of a test as scalars, returns a new
38L<TAP::Parser::Scheduler::Job> object.
f7c69158
NC
39
40=cut
41
42sub new {
43 my ( $class, $name, $desc, @ctx ) = @_;
44 return bless {
45 filename => $name,
46 description => $desc,
27fc0087 47 @ctx ? ( context => \@ctx ) : (),
f7c69158
NC
48 }, $class;
49}
50
dbd04185
NC
51=head2 Instance Methods
52
f7c69158
NC
53=head3 C<on_finish>
54
dbd04185
NC
55 $self->on_finish(\&method).
56
57Register a closure to be called when this job is destroyed. The callback
58will be passed the C<TAP::Parser::Scheduler::Job> object as it's only argument.
f7c69158
NC
59
60=cut
61
62sub on_finish {
63 my ( $self, $cb ) = @_;
64 $self->{on_finish} = $cb;
65}
66
67=head3 C<finish>
68
dbd04185
NC
69 $self->finish;
70
71Called when a job is complete to unlock it. If a callback has been registered
72with C<on_finish>, it calls it. Otherwise, it does nothing.
f7c69158
NC
73
74=cut
75
76sub finish {
77 my $self = shift;
78 if ( my $cb = $self->{on_finish} ) {
79 $cb->($self);
80 }
81}
82
dbd04185
NC
83=head2 Attributes
84
85 $self->filename;
86 $self->description;
87 $self->context;
88
89These are all "getters" which return the data set for these attributes during object construction.
90
91
f7c69158
NC
92=head3 C<filename>
93
94=head3 C<description>
95
96=head3 C<context>
97
98=cut
99
100sub filename { shift->{filename} }
101sub description { shift->{description} }
27fc0087 102sub context { @{ shift->{context} || [] } }
f7c69158
NC
103
104=head3 C<as_array_ref>
105
106For backwards compatibility in callbacks.
107
108=cut
109
110sub as_array_ref {
111 my $self = shift;
27fc0087 112 return [ $self->filename, $self->description, $self->{context} ||= [] ];
f7c69158
NC
113}
114
115=head3 C<is_spinner>
116
dbd04185
NC
117 $self->is_spinner;
118
f7c69158
NC
119Returns false indicating that this is a real job rather than a
120'spinner'. Spinners are returned when the scheduler still has pending
121jobs but can't (because of locking) return one right now.
122
123=cut
124
125sub is_spinner {0}
126
1271;