Sprog::Gear.3pm

Langue: en

Version: 2005-07-25 (fedora - 01/12/10)

Section: 3 (Bibliothèques de fonctions)

NAME

Sprog::Gear - Base class for Sprog gears

SYNOPSIS

   use base qw(Sprog::Gear);
 
   __PACKAGE__->declare_properties(
     filename   =>  '',
   );
 
 

DESCRIPTION

This is the base class which all Sprog gear classes should inherit from. It provides default behaviours as described below:

CLASS METHODS

new ( arguments )

The constructor. Creates a gear object and initialises it from the supplied arguments as well as from the gear metadata section (see: Sprog::GearMetadata).

declare_properties ( name => default ... )

Defines property names and default values. Usually called in the gear class as shown in the synopsis above.

INSTANCE METHODS

alert ( message, detail )

Requests the main application window to pop up a message dialog to display the alert message and optional extra detail.

An alert is a 'fatal' error - it will terminate the machine startup or stop the machine if it's already running.

app ( )

Returns a reference to the Sprog application object.

disengage ( )

A gear would call this method to signal to the scheduler that it is finished and will be sending no more messages.

engage ( )

The scheduler will call this method on each gear as it prepares to run the machine. A gear class should override this method to do any necessary initialisation and then either return a false value if initialisation failed, or call "SUPER::engage"

has_input ( )

Returns true if the gear has an input connector.

has_output ( )

Returns true if the gear has an output connector.

id ( )

An integer which uniquely identifies the gear.

input_type ( )

Returns a single character (currently 'P', 'A' or 'H') indicating the type of input connector or '_' if the gear has no input connector. Populated automatically from the gear metadata.

last ( )

Returns a reference to the last gear in the chain - which may be the current gear.

machine ( )

Returns a reference to the Sprog::Machine object.

msg_out ( msg_name => arguments )

Send a message to the next gear.

msg_queue ( )

Returns a reference to the array of waiting messages. Useful for peeking to see what's coming up.

next ( )

Returns a reference to the next gear.

no_more_data ( )

The scheduler will call this method when the preceding gear has disengaged. The default implementation will disengage the current gear.

no_properties ( )

Returns true if the gear has no user-configurable properties (and therefore the properties option should be greyed out on the gear menu).

output_type ( )

Returns a single character (currently 'P', 'A' or 'H') indicating the type of output connector or '_' if the gear has no output connector. Populated automatically from the gear metadata.

requeue_message_delayed ( msg_name => arguments )

Gives a message back to the scheduler and asks it to re-deliver the message when the next message arrives. Useful for reassembing fragmented data.

scheduler ( )

Returns a reference to the scheduler object - undef if the machine is not running.

serialise ( )

Called when the machine is saved to a file. The default implementation returns a reference to a hash containing only those property values which would be required to reconstruct the object. The machine class will serialise that hashref using whatever means it sees fit (currently YAML).

sleeping ( boolean )

A gear will set this flag to indicate that it is currently sleeping (eg: waiting for an IO event). The scheduler will not attempt to deliver any messages to it (or remove it from the machine) until it wakes up.

stop ( )

Called by the scheduler when the machine is stopped - gives gears a chance to release resources (eg: close files).

title ( )

Called by the gear view class to determine what label to display on the gear. Populated automatically from the gear metadata.

view_subclass ( )

Returns the name of the class which will handle the user interface. Populated automatically from the gear metadata.

work_done ( boolean )

Used to tell the gear view class to indicate visually that the gear is working (a cog is turned). The scheuler will set this flag when it delivers a message. The gear view will reset it when it indicates work done. The gear class itself will ignore it.

x ( )

The X position of the gear on the workspace.

y ( )

The Y position of the gear on the workspace.

SEE ALSO

Sprog gears exist within a Sprog::Machine, which in turn provides the data model for a Sprog application.

More information for developers is available in gear internals.

Copyright 2004-2005 Grant McLean <grantm@cpan.org>

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