The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Net::NodeTransformator - interface to node transformator

VERSION

version 0.105

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([$connect|%options])

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.

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.

Use $options{cb} to set a callback handler, to avoid blocking.

        Net::NodeTransformator->standalone(cb => sub {
                my $nnt = shift->recv; # croaks on error
        });

Alternativly, use $options{cv} to use the condvar directly

        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

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 used
input The input string
data (optional) Additional data to be send with. Currently only meaningful for jade engine.
cv (optional) An own AnyEvent::CondVar
cb (optional) A callback handler
        $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.

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)

BUGS

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.

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