Padre::Wx::Role::Idle(3pm)

Padre::Wx::Role::Idle3pm

Role for delaying method calls until idle time

Usage

  # Manually schedule some work on idle
  $self->idle_method( my_method => 'param' );
  
  # Delay work until idle time in response to an event
  Wx::Event::EVT_TREE_ITEM_ACTIVATED(
      $self,
      $self,
      sub {
            shift->idle_method( my_method => 'param' );
      },
  );
  
  # The handler for the event
  sub my_method {
      my $self  = shift;
      my $param = shift;
      
      # Functionality is implemented here
  }

Overview

This role provides a standard mechanism for delaying method call dispatch until idle time.

The role maintains a dispatch queue for each object, binds or unbinds an "EVT_IDLE" handler depending on whether there is anything in the queue, and dispatches one method from the queue each time idle is fired (to ensure that any large series of tasks will be spread out over time instead of all blocking at once on the first idle event).

Methods

idle_method

  $self->idle_method( method_name => @params );

The "idle_method" method is used to schedule a method for execution at idle time.

The first parameter to the call should be the name of the method to be called on this object. The method will be checked before it is added to the queue to ensure that it exists.

Any remaining parameters to "idle_method" will be passed through as parameters to the specified method call.

Please note that Wx::Event objects must not be used as parameters to this method. While the Perl level object will survive until idle time, the underlying Wx event structure for the event will no longer exist, and any attempt to call a method on the event object will segfault Perl.

You should unpack any information you need from the Wx::Event before making the call to "idle_method" and pass it through as data instead.

idle_handler

The "idle_handler" method is called internally to dispatch the next method in the idle queue.

It will dispatch one and only one call on the queue, returning true if there are any remaining calls on the queue of false if the queue is empty.

While you generally should not need to know about this method, there are two ways to use this method to influence the behaviour of the role.

Firstly, the method call be called directly to trigger the immediate dispatch of an idle method without waiting for the "EVT_IDLE" event to fire.

Secondly, you could overload the "idle_handler" method to add extra functionality that should be run any time a delayed call of any other type is made.

Releases

2 releases since Debian 7 (Wheezy); the text changed 1 time.

  1. 7
  2. 8

From padre 1.00+dfsg-3 in Debian 8 (Jessie). Parsed by carta from the page's man source.