Pinto
view release on metacpan or search on metacpan
lib/Pinto/Remote/Action.pm view on Meta::CPAN
return ( chrome => encode_json($chrome_args) );
}
#------------------------------------------------------------------------------
sub _pinto_args {
my ($self) = @_;
my $pinto_args = { username => $self->username };
return ( pinto => encode_json($pinto_args) );
}
#------------------------------------------------------------------------------
sub _action_args {
my ($self) = @_;
my $action_args = $self->args;
return ( action => encode_json($action_args) );
}
#------------------------------------------------------------------------------
sub _send_request {
my ( $self, %args ) = @_;
my $request = $args{req} || $self->_make_request;
my $status = 0;
# Currying in some extra args to the callback...
my $callback = sub { $self->_response_callback( \$status, @_ ) };
my $response = $self->ua->request( $request, $callback );
if ( not $response->is_success ) {
$self->error( $response->content );
return Pinto::Result->new( was_successful => 0 );
}
return Pinto::Result->new( was_successful => $status );
}
#------------------------------------------------------------------------------
sub _response_callback {
my ( $self, $status, $data ) = @_;
# Each data chunk will be one or more lines ending with \n
chomp $data;
if ( not $data ) {
# HACK: So that blank lines come out right
# Need to find a better way to do this!!
$self->chrome->show('');
return 1;
}
for my $line ( split m/\n/, $data, -1 ) {
if ( $line eq $PINTO_SERVER_STATUS_OK ) {
${$status} = 1;
}
elsif ( $line eq $PINTO_SERVER_PROGRESS_MESSAGE ) {
$self->chrome->show_progress;
}
elsif ( $line eq $PINTO_SERVER_NULL_MESSAGE ) {
# Do nothing, discard message
}
elsif ( $line =~ m{^ \Q$PINTO_SERVER_DIAG_PREFIX\E (.*)}x ) {
$self->chrome->diag($1);
}
else {
$self->chrome->show($line);
}
}
return 1;
}
#-----------------------------------------------------------------------------
__PACKAGE__->meta->make_immutable;
#------------------------------------------------------------------------------
1;
__END__
=pod
=encoding UTF-8
=for :stopwords Jeffrey Ryan Thalhammer BenRifkah Fowler Jakob Voss Karen Etheridge Michael
G. Bergsten-Buret Schwern Oleg Gashev Steffen Schwigon Tommy Stanton
Wolfgang Kinkeldei Yanick Boris Champoux hesco popl Däppen Cory G Watson
David Steinbrunner Glenn
=head1 NAME
Pinto::Remote::Action - Base class for remote Actions
=head1 VERSION
version 0.097
=head1 METHODS
=head2 execute
Runs this Action on the remote server by serializing itself and
sending a POST request to the server. Returns a L<Pinto::Result>.
=head1 AUTHOR
Jeffrey Ryan Thalhammer <jeff@stratopan.com>
=head1 COPYRIGHT AND LICENSE
( run in 0.580 second using v1.01-cache-2.11-cpan-71847e10f99 )