Sprog::help::gear_mixins.3pm

Langue: en

Autres versions - même langue

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

Section: 3 (Bibliothèques de fonctions)

Gear Mixin Classes

If you're writing your own gear classes, you may wish to use some of the available 'mixin' classes to add capabilities to you gear. You use them by setting up your class to inherit from them. For example:
   use base qw(
     Sprog::Mixin::InputByLine
     Sprog::Gear
   );
 
 

Line-by-Line Input

Gear classes with a 'pipe' style input connector receive their input as a series of "data" messages. The data in these messages is in arbitrarily sized chunks. There's no guarantee that a chunk won't end part-way through a line.

The Sprog::Mixin::InputByLine mixin class implements a 'data' method that buffers up partial lines and passes each complete one to a "line" method that you implement.

Paragraph-at-a-Time Input

The Sprog::Mixin::InputByPara mixin class implements a 'data' method that buffers up a paragraphs of input and passes each complete one to a "para" method that you implement. Paragraphs are assumed to be separated by blank lines.

File-at-a-Time Input

The Sprog::Mixin::SlurpFile mixin class implements a 'data' method that buffers up a whole file and passes all the data to a "file_data" method that you implement.

Input From Filehandle

Any class that reads from a file, pipe or socket will need to use non-blocking IO. The Sprog::Mixin::InputFromFH mixin class interfaces to the Gtk event loop and adds an IO watch on the filehandle you provide. When data becomes available, an outgoing "data" message will be generated, but you can intercept that and massage the data by overriding the "msg_out" method.

Output To Filehandle

Any class that writes to a file, pipe or socket will need to use non-blocking IO. The Sprog::Mixin::OutputToFH mixin class interfaces to the Gtk event loop and adds an IO watch on the filehandle you provide. Incoming "data" messages are buffered. When the filehandle becomes writeable, data is written out from the buffer. When no more data is available and the buffer has been drained, the gear will disengage itself.