File Coverage

lib/Rex/Template/Mojo.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             #
2             # (c) James King
3             #
4             # vim: set ts=4 sw=4 tw=0:
5             # vim: set expandtab:
6              
7             =head1 NAME
8              
9             Rex::Template::Mojo - Use Mojo::Template with Rex
10              
11             =head1 DESCRIPTION
12              
13             This module enables the use of Mojo::Template for Rex Templates.
14              
15             =head1 USAGE
16              
17             Just include the file into your I.
18              
19             # Rexfile
20             use Rex::Template::Mojo;
21            
22             task prepare => sub {
23            
24             file "/a/file/on/the/remote/machine.conf",
25             content => template("path/to/your/template.tt",
26             var1 => $var1,
27             arr1 => \@arr1,
28             hash1 => \%hash1,
29             );
30            
31             };
32              
33             =cut
34              
35             package Rex::Template::Mojo;
36              
37 1     1   4866 use strict;
  1         2  
  1         37  
38 1     1   5 use warnings;
  1         3  
  1         48  
39              
40             our $VERSION = "1.0";
41              
42 1     1   1063 use Mojo::Template;
  1         125087  
  1         14  
43 1     1   491 use Rex -base;
  0            
  0            
44             use 5.010;
45              
46             sub import {
47             set template_function => sub {
48             my ( $content, $vars ) = @_;
49             my $t = Mojo::Template->new;
50             return $t->render( $content, $vars );
51             };
52             }
53              
54             1;
55