Padre::Service - persistent Padre::Task API
# 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
Padre::Service extends Padre::Task to provide a means to launch and control a long running background service, without blocking the editor.
To extend this class, inherit it and implement service_loop and preferabbly hangup
service_loop
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.
<Task-
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 }
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.
Padre::Task::run
run
consider start the background_thread analog of prepare and will be called in the service thread immediatly prior to the service loop starting.
prepare
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
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.
<-
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.
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
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
enqueue
Accepts a reference as it's argument, this is serialized and sent to the service thread
Copyright 2009 The Padre develoment 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.
To install Padre, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Padre
CPAN shell
perl -MCPAN -e shell install Padre
For more information on module installation, please visit the detailed CPAN module installation guide.