Agent-TCLI

 view release on metacpan or  search on metacpan

lib/Agent/TCLI/Package/UnixBase.pm  view on Meta::CPAN

					:All('child');


# Standard class utils are inherited

=back

See Agent::TCLI::Package::Base for other attributes applicable to Packages.

=head2 METHODS

These simple methods may be used as is, or subclasses may use them as
starting point.

=over

=item RunWheelStart

This initializes the POE::Component::Child session. It may be called
from a Package's _start routine or the contents may be copied for further
modification.

=cut

sub RunWheelStart {
	my $self = shift;

	$self->child( POE::Component::Child->new(
		alias => $self->name,
#		debug => $self->verbose,
	));

#	$self->child->{'StdioFilter'} = POE::Filter::Stream->new;
}

=item stdout

This POE event handler is the default way stdout lines are returned from
the child command being run.

=cut

sub stdout {
    my ($kernel,  $self, $child, $resp) =
      @_[KERNEL, OBJECT,   ARG0,  ARG1];
	$self->Verbose("stdout: wheel_id(".$resp->{'wheel'}.") ",1);

    my $request = $self->GetWheelKey( $resp->{'wheel'}, 'request' );
	my $output = $resp->{'out'};

	unless ( ref($request) =~ qr(Request) )
	{
		$self->Verbose("stdout: wid(".$resp->{'wheel'}.")no request for output($output)",0);
		return;
	}
	$self->Verbose("stdout: rid (".$request->id.")  wid(".$resp->{'wheel'}.")" );

	$request->Respond( $kernel, $output, 200);
}

=item stderr

This POE event handler is the default way stderr lines are returned from
the child command being run.

=cut

sub stderr {
    my ($kernel,  $self, $child, $resp) =
      @_[KERNEL, OBJECT,   ARG0,  ARG1];
	$self->Verbose("stderr: wheel_id(".$resp->{'wheel'}.") ",1);

    my $request = $self->GetWheelKey( $resp->{'wheel'}, 'request' );

	my $output = "STDERR: ".$resp->{'out'}." !!! ";

	$request->Respond( $kernel, $output, 400);
}

=item error

This POE event handler is the default way errors are returned from
the child command being run.

=cut

sub error {
    my ($kernel,  $self, $operation, $errnum, $errstr, $wheel_id) =
      @_[KERNEL, OBJECT,       ARG0,    ARG1,    ARG2,     ARG3];

    $errstr = "remote end closed" if $operation eq "read" and !$errnum;
	my $output = "Wheel $wheel_id generated $operation error $errnum: $errstr\n";

	$self->Verbose("error: output($output)",2);
    my $request = $self->GetWheelKey( $wheel_id, 'request' );

	$request->Respond( $kernel, $output, 400) if defined($request);
}

=item done

This POE event handler is the default way a child indicates that it is
done.

=cut

sub done {
    my ($self, $child, $resp) = @_[OBJECT, ARG0, ARG1];
#    my $child = $self->GetWheel( $resp->id );
    $self->Verbose( "done: wheel (".$resp->{'wheel'}." ) has finished.");
    #remove wheel reference
	$self->SetWheel($resp->{'wheel'});
}

1;

=back

=head3 INHERITED METHODS

This module is an Object::InsideOut object that inherits from
Agent::TCLI::Package::Base. It inherits methods from both.
Please refer to their documentation for more details.

=head1 AUTHOR

Eric Hacker	 E<lt>hacker at cpan.orgE<gt>

=head1 BUGS

SHOULDS and MUSTS are currently not enforced.



( run in 1.427 second using v1.01-cache-2.11-cpan-39bf76dae61 )