| 1 |
package Test2::Harness::IPC::Process; |
| 2 |
use strict; |
| 3 |
use warnings; |
| 4 |
|
| 5 |
our $VERSION = '1.000179'; |
| 6 |
|
| 7 |
use Carp qw/croak/; |
| 8 |
|
| 9 |
use Test2::Harness::Util::HashBase qw{ |
| 10 |
<exit <exit_time |
| 11 |
<pid |
| 12 |
+category |
| 13 |
}; |
| 14 |
|
| 15 |
sub category { $_[0]->{+CATEGORY} //= 'default' } |
| 16 |
|
| 17 |
sub set_pid { |
| 18 |
my $self = shift; |
| 19 |
my ($pid) = @_; |
| 20 |
|
| 21 |
croak "pid has already been set" if defined $self->{+PID}; |
| 22 |
|
| 23 |
$self->{+PID} = $pid; |
| 24 |
} |
| 25 |
|
| 26 |
sub set_exit { |
| 27 |
my $self = shift; |
| 28 |
my ($ipc, $exit, $time) = @_; |
| 29 |
|
| 30 |
croak "exit has already been set" if defined $self->{+EXIT}; |
| 31 |
|
| 32 |
$self->{+EXIT} = $exit; |
| 33 |
$self->{+EXIT_TIME} = $time; |
| 34 |
} |
| 35 |
|
| 36 |
sub spawn_params { |
| 37 |
my $self = shift; |
| 38 |
my $class = ref($self) || $self; |
| 39 |
|
| 40 |
croak "Process class '$class' does not implement 'spawn_params()'"; |
| 41 |
} |
| 42 |
|
| 43 |
1; |
| 44 |
|
| 45 |
__END__ |
| 46 |
|
| 47 |
=pod |
| 48 |
|
| 49 |
=encoding UTF-8 |
| 50 |
|
| 51 |
=head1 NAME |
| 52 |
|
| 53 |
Test2::Harness::IPC::Process - Base class for processes controlled by |
| 54 |
Test2::Harness::IPC. |
| 55 |
|
| 56 |
=head1 DESCRIPTION |
| 57 |
|
| 58 |
All processes controlled by L<Test2::Harness::IPC> should subclass this one. |
| 59 |
|
| 60 |
=head1 ATTRIBUTES |
| 61 |
|
| 62 |
=over 4 |
| 63 |
|
| 64 |
=item $int = $proc->exit |
| 65 |
|
| 66 |
Exit value, if set. Otherwise C<undef>. |
| 67 |
|
| 68 |
=item $stamp = $proc->exit_time |
| 69 |
|
| 70 |
Timestamp of the process exit, if set, otherwise C<undef>. |
| 71 |
|
| 72 |
=item $pid = $proc->pid |
| 73 |
|
| 74 |
Pid of the process, if it has been started. |
| 75 |
|
| 76 |
=item $cat = $proc->category |
| 77 |
|
| 78 |
Set at construction, C<'default'> if not provided. |
| 79 |
|
| 80 |
=back |
| 81 |
|
| 82 |
=head1 METHODS |
| 83 |
|
| 84 |
=over 4 |
| 85 |
|
| 86 |
=item $opt->set_pid($pid) |
| 87 |
|
| 88 |
Set the process id. |
| 89 |
|
| 90 |
=item $opt->set_exit($ipc, $exit, $time) |
| 91 |
|
| 92 |
Set the process as complete. $exit should be the exit value. $time should be a |
| 93 |
timestamp. $ipc is an instance of L<Test2::Harness::IPC>. |
| 94 |
|
| 95 |
=item $hashref = $opt->spawn_params() |
| 96 |
|
| 97 |
Used when spawning the process, args go to C<run_cmd()> from |
| 98 |
L<Test2::Harness::Util::IPC>. |
| 99 |
|
| 100 |
The base class throws an exception if this method is called. |
| 101 |
|
| 102 |
=back |
| 103 |
|
| 104 |
=head1 SOURCE |
| 105 |
|
| 106 |
The source code repository for Test2-Harness can be found at |
| 107 |
F<http://github.com/Test-More/Test2-Harness/>. |
| 108 |
|
| 109 |
=head1 MAINTAINERS |
| 110 |
|
| 111 |
=over 4 |
| 112 |
|
| 113 |
=item Chad Granum E<lt>[email protected]<gt> |
| 114 |
|
| 115 |
=back |
| 116 |
|
| 117 |
=head1 AUTHORS |
| 118 |
|
| 119 |
=over 4 |
| 120 |
|
| 121 |
=item Chad Granum E<lt>[email protected]<gt> |
| 122 |
|
| 123 |
=back |
| 124 |
|
| 125 |
=head1 COPYRIGHT |
| 126 |
|
| 127 |
Copyright 2020 Chad Granum E<lt>[email protected]<gt>. |
| 128 |
|
| 129 |
This program is free software; you can redistribute it and/or |
| 130 |
modify it under the same terms as Perl itself. |
| 131 |
|
| 132 |
See F<http://dev.perl.org/licenses/> |
| 133 |
|
| 134 |
=cut |