NAME
Net::NodeTransformator - interface to node transformator
VERSION
version 0.103
SYNOPSIS
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);
DESCRIPTION
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.
METHODS
new($hostport)
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');
standalone([$hostport])
Starts a transformator standalone server. If $hostport
is omitted, a temporary directory will be created and a unix domain socket will be placed in it.
Returns a ready-to-use Net::NodeTransformator instance.
Net::NodeTransformator->standalone;
cleanup
Stopps a previously started standalone server.
transform_cv(%options)
Connects to transformator and waits for the result asynchronously by using a condition variable.
%options requires for keyworks:
engine
The engine to be usedinput
The input stringdata
(optional) Additional data to be send with. Currently only meaningful for jade engine.on_error
A callback subroutine called in case of any 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.
transform($engine, $input, $data)
This is the synchronous variant of transform_cv
. It croaks on error and can be catched by Try::Tiny for example.
SHORTCUT METHODS
This list is incomplete. I will add more methods on request. All methods are hopefully self-describing.
jade($input, $data)
coffeescript($input)
minify_html($input)
minify_css($input)
minify_js($input)
AUTHOR
David Zurborg <zurborg@cpan.org>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2014 by David Zurborg.
This is free software, licensed under:
The ISC License