Net::NodeTransformator - interface to node transformator
version 0.105
use Net::NodeTransformator; my $nnt = Net::NodeTransformator->new; my $jade_in = <<'EOT'; span | Hi #{name}! EOT my $jade_vars = { name => 'Peter' }; my $jade_out = $nnt->jade($jade_in, $jade_vars);
This module is an interface to the transformator package of nodejs. See https://www.npmjs.org/package/transformator for more information about the server.
When it's difficult for perl to interact with various nodejs packages, the transformator protocol allows everyone to interact with an nodejs service. transformator supports a vast range of libraries like jade-lang, sass-lang or coffeescript.
The other way is to invoke each command-line tool as a child process, but this may be very inefficient if such tool need to be called frequently.
Set the hostname/port or unix domain socket for connecting to transformator.
Net::NodeTransformator->new('12345'); Net::NodeTransformator->new('localhost:12345'); Net::NodeTransformator->new('path/to/unix/domain/socket');
Starts a transformator standalone server. If $connect or $options{connect} is omitted, a temporary directory will be created and a unix domain socket will be placed in it.
$connect
$options{connect}
Returns a ready-to-use Net::NodeTransformator instance.
my $nnt = Net::NodeTransformator->standalone; # croaks on error
Use $options{bin} to either name the binary that could be found in $PATH or name a direct path to the binary. Defaults to transformator.
$options{bin}
Use $options{cb} to set a callback handler, to avoid blocking.
$options{cb}
Net::NodeTransformator->standalone(cb => sub { my $nnt = shift->recv; # croaks on error });
Alternativly, use $options{cv} to use the condvar directly
$options{cv}
my $cv = Net::NodeTransformator->standalone(cv => 1); my $nnt = $cv->recv; # croaks on error
In both cases, a condvar is returned. An own condvar can also be used:
my $cv = AE::cv; Net::NodeTransformator->standalone(cv => $cv); $cv->recv; # croaks on error
Stopps a previously started standalone server.
Connects to transformator and waits for the result asynchronously by using a condition variable.
%options requires for keyworks:
engine
input
data
cv
cb
$nnt->transform_cv(..., cb => sub { my $result = shift->recv; # croaks on error });
This method returns a condition variable (AnyEvent::CondVar)
my $cv = $nnt->transform_cv(...);
The result will be pushed to the condvar, so $cv->recv will return the result or croaks on error.
$cv->recv
This is the synchronous variant of transform_cv. It croaks on error and can be catched by Try::Tiny for example.
transform_cv
This list is incomplete. I will add more methods on request. All methods are hopefully self-describing.
Please report any bugs or feature requests on the bugtracker website https://github.com/zurborg/libnet-nodetransformator-perl/issues
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
David Zurborg <zurborg@cpan.org>
This software is Copyright (c) 2014 by David Zurborg.
This is free software, licensed under:
The ISC License
To install Net::NodeTransformator, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::NodeTransformator
CPAN shell
perl -MCPAN -e shell install Net::NodeTransformator
For more information on module installation, please visit the detailed CPAN module installation guide.