sungo > POE-Component-SubWrapper > POE::Component::SubWrapper

Download:
POE-Component-SubWrapper-0.09.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 2.01   Source  

NAME ^

POE::Component::SubWrapper - event based wrapper for subs

SYNOPSIS ^

  use POE::Component::SubWrapper;
  POE::Component::SubWrapper->spawn('main');
  $kernel->post('main', 'my_sub', [ $arg1, $arg2, $arg3 ], 'callback_state');

DESCRIPTION ^

This is a module which provides an event based wrapper for subroutines.

METHODS ^

spawn

  POE::Component::SubWrapper->spawn('main');

SubWrapper components are not normal objects, but are instead 'spawned' as separate sessions. This is done with with PoCo::SubWrapper's 'spawn' method, which takes one required and one optional argument. The first argument is the package name to wrap. This is required. The second argument is optional and contains an alias to give to the session created. If no alias is supplied, the package name is used as an alias.

poeize

  poeize My::Package;

Another way to create SubWrapper components is to use the poeize method, which is included in the default export list of the package. You can simply do:

  poeize Data::Dumper;

and Data::Dumper will be wrapped into a session with the alias 'Data::Dumper'.

STATES ^

When a SubWrapper component is created, it scans the package named for subroutines, and creates one state in the session created with the same name of the subroutine.

The states each accept 3 arguments:

EXAMPLES ^

The test scripts are the best place to look for examples of POE::Component::Subwrapper usage. A short example is given here:

  use Data::Dumper;
  poeize Data::Dumper;
  $kernel->post('Data::Dumper', 'Dumper', [ { a => 1, b => 2 } ], 'callback_state', 'SCALAR');

  sub callback_handler {
    my $result = @_[ARG0];
    # do something with the string returned by Dumper({ a => 1, b => 2})
  }

Data::Dumper is the wrapped module, Dumper is the function called, {a => 1, b => 2} is the data structure that is dumped, and $result is the resulting string form.

EXPORT

The module exports the following functions by default:

poeize

A function called with a single bareword argument specifying the package to be wrapped.

AUTHOR ^

Matt Cashner (sungo@pobox.com)

Michael Stevens - michael@etla.org

LICENSE ^

Copyright (c) 2000-2002 Michael Stevens

Copyright (c) 2002-2004 Matt Cashner

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

syntax highlighting: