NAME

Padre::Service - persistent Padre::Task API

SYNOPSIS

  # Create your service, default implementation warns to output
  #  sleeps 1 second and loops over.
  my $service = Padre::Service->new();
  Wx::Event::EVT_COMMAND(
	$main , -1 , $service->event ,
	\&receive_data_from_service
  );
  $service->schedule;
  $service->


  # Later
  $service->shutdown; # Your show_my_dialog will be called...,eventually

DESCRIPTION

Padre::Service extends Padre::Task to provide a means to launch and control a long running background service, without blocking the editor.

EXTENDING

To extend this class, inherit it and implement service_loop and preferably hangup.

service_loop should not block forever. If there is no work for the service to do then return immediately, allowing the Task->run loop to continue.

package Padre::Service::HTTPD
use base qw( Padre::Service );

sub prepare { # Build a dummy httpd.conf from $self , "BREAK" if error }

sub service_start { # Launch httpd binary goodness, IPC::Run3 maybe? }

sub service_shutdown { # Clean shutdown httpd binary }

sub service_loop { # ->select($timeout) on your IPC handles }

sub hangup { ->service_shutdown ?!?}

sub terminate { # Stop everything, brutally }

METHODS

run

Overrides Padre::Task::run providing a non-blocking loop around the TaskManager to Service shared queue.

run will call hangup or terminate on your service if instructed by the main thread, otherwise service_loop is called in void context with no arguments in a tight loop.

start

consider start the background_thread analog of prepare and will be called in the service thread immediately prior to the service loop starting.

hangup

Called on your service when the editor requests a hangup. Your service is obliged to gracefully stop what it is doing and return from this method as soon as possible

terminate

Called on your service when TaskManager believes your service is hung or not responding to a <-hangup>. Your service is obliged to IMMEDIATELY stop everything and to hell with the consequences.

service_loop

Called in a loop while the service is believed to be running The default implementation emits output to the editor and sleeps for a second before returning control to the loop.

event

Accessor for this service's instance event, in the running service data may be posted to this event and the Wx subscribers will be notified

queue

accessor for the shared queue the service thread is polling for input. Calling enqueue on reference sends data to the service thread. Storable serialization rules apply. See also "event" for receiving data from the service thread

tell

Accepts a reference as it's argument, this is serialized and sent to the service thread

COPYRIGHT

Copyright 2008-2010 The Padre development team as listed in Padre.pm

This program is free software; you can redistribute it and/or modify it under the same terms as Perl 5 itself.