File Coverage

blib/lib/Template/Plugin/Filter/PlantUML.pm
Criterion Covered Total %
statement 25 25 100.0
branch n/a
condition 1 2 50.0
subroutine 8 8 100.0
pod 2 2 100.0
total 36 37 97.3


line stmt bran cond sub pod time code
1             package Template::Plugin::Filter::PlantUML;
2              
3 2     2   626438 use 5.006;
  2         10  
4 2     2   14 use strict;
  2         6  
  2         69  
5 2     2   24 use warnings;
  2         16  
  2         210  
6              
7             require Template::Plugin::Filter;
8 2     2   15 use base qw(Template::Plugin::Filter);
  2         6  
  2         1491  
9 2     2   10600 use vars qw($VERSION $DYNAMIC $FILTER_NAME);
  2         7  
  2         217  
10              
11 2     2   1130 use WWW::PlantUML;
  2         259570  
  2         518  
12              
13             =for html  
14              
15             =head1 NAME
16              
17             Template::Plugin::Filter::PlantUML - A template toolkit plugin filter for encoding and processing PlantUML Diagrams using a PlantUML Server.
18              
19             =head1 VERSION
20              
21             Version 0.02
22              
23             =cut
24              
25             our $VERSION = 0.02;
26             our $DYNAMIC = 1;
27             our $FILTER_NAME = 'plantuml';
28              
29             =head1 SYNOPSIS
30              
31             To use this plugin, you have to make sure that the Template Toolkit knows about its namespace.
32              
33             my $tt2 = Template->new({
34             PLUGIN_BASE => 'Template::Plugin::Filter',
35             });
36              
37             # or
38              
39             my $tt2 = Template->new({
40             PLUGINS => {
41             PlantUML => 'Template::Plugin::Filter::PlantUML',
42             },
43             });
44              
45             Then you C your plugin in a template file as follows.
46              
47             [% USE 'http://www.plantuml.com/plantuml' 'svg' -%]
48            
49             [% url = FILTER plantuml %]
50             Bob -> Alice : hello
51             [% END %]
52            
53            
54              
55             Finally process your template.
56              
57             $tt2->process('foo.tt2') || die $tt2->error();
58              
59             Result would be:
60              
61            
62              
63             =head1 EXAMPLE
64              
65             =begin HTML
66              
67            

Live Example from PlantUML.com

68              
69             =end HTML
70              
71             =head1 DESCRIPTION
72              
73             This is a trivial Template::Toolkit plugin filter to allow any template writer to embed PlantUML Diagram Syntax in Templates and have them encoded and processed via any PlantUML Server in any supported formats.
74              
75             It uses C remote client under the hood.
76              
77             =head1 SUBROUTINES/METHODS
78              
79             =head2 init
80              
81             defines init() method.
82              
83             =cut
84              
85             sub init {
86 1     1 1 115 my $self = shift;
87 1         12 $self->install_filter($FILTER_NAME);
88 1         137 return $self;
89             }
90              
91             =head2 filter
92              
93             defines filter() method.
94              
95             =cut
96              
97             sub filter {
98 1     1 1 151 my ( $self, $code, $args, $conf ) = @_;
99              
100 1         10 $args = $self->merge_args($args);
101 1         18 $conf = $self->merge_config($conf);
102              
103 1         17 my $puml = WWW::PlantUML->new( @$args[0] );
104 1   50     28 return $puml->fetch_url( $code, @$args[1] || 'png' );
105             }
106              
107             =head1 AUTHOR
108              
109             Rangana Sudesha Withanage, C<< >>
110              
111             =head1 BUGS
112              
113             Please report any bugs or feature requests to C, or through
114             the web interface at L. I will be notified, and then you'll
115             automatically be notified of progress on your bug as I make changes.
116              
117              
118             =head1 SUPPORT
119              
120             You can find documentation for this module with the perldoc command.
121              
122             perldoc Template::Plugin::Filter::PlantUML
123              
124              
125             You can also look for information at:
126              
127             =over 4
128              
129             =item * RT: CPAN's request tracker (report bugs here)
130              
131             L
132              
133             =item * GitHub Repository
134              
135             L
136              
137             =item * CPAN Ratings
138              
139             L
140              
141             =item * Search CPAN
142              
143             L
144              
145             =back
146              
147              
148             =head1 ACKNOWLEDGEMENTS
149              
150             Many thanks to Andy Wardley L for his awesome L
151              
152             =head1 LICENSE AND COPYRIGHT
153              
154             This software is copyright (c) 2019 by Rangana Sudesha Withanage.
155              
156             This is free software; you can redistribute it and/or modify it under
157             the same terms as the Perl 5 programming language system itself.
158              
159              
160             =cut
161              
162             1; # End of Template::Plugin::Filter::PlantUML