File Coverage

blib/lib/WWW/PlantUML.pm
Criterion Covered Total %
statement 22 22 100.0
branch 1 2 50.0
condition 1 3 33.3
subroutine 6 6 100.0
pod 2 2 100.0
total 32 35 91.4


line stmt bran cond sub pod time code
1             package WWW::PlantUML;
2              
3 2     2   293722 use 5.006;
  2         10  
4 2     2   14 use strict;
  2         7  
  2         133  
5 2     2   15 use warnings;
  2         10  
  2         161  
6              
7 2     2   1323 use UML::PlantUML::Encoder qw(encode_p);
  2         244724  
  2         690  
8              
9             =for html  
10              
11             =head1 NAME
12              
13             WWW::PlantUML - a simple Perl remote client interface to a plantuml server.
14              
15             =head1 VERSION
16              
17             Version 0.03
18              
19             =cut
20              
21             our $VERSION = '0.03';
22             our $URL = 'http://www.plantuml.com/plantuml';
23              
24             =head1 SYNOPSIS
25              
26             use WWW::PlantUML;
27              
28             my $puml = WWW::PlantUML->new;
29             my $url = $puml->fetch_url(qq{
30             Alice -> Bob : hello
31             }, 'png');
32              
33             print $url;
34             # prints http://www.plantuml.com/plantuml/png/~169NZKb1GSCp9J4vLqBLJSCfFKh1Io4ZDoSdd0W1EMmQV
35              
36             =head1 DESCRIPTION
37              
38             Plantuml is a library for generating UML diagrams from a simple text markup language.
39              
40             This is a simple Perl remote client interface to a plantuml server using the same custom encoding used by most other plantuml clients. Perl was missing from the list.
41              
42             There are other plantuml Perl libraries, like PlantUML::ClassDiagram::Parse, they provide only parsing capabilities for Class Diagrams. In contrast WWW::PlantUML module provides accessing any UML Diagram Type in various formats supported by any plantUML server via HTTP Protocol.
43              
44             This client defaults to the public plantuml server, but can be used against any server.
45              
46             =head1 SUBROUTINES/METHODS
47              
48             =head2 new
49              
50             Constructor.
51              
52             Can be optionally passed a URL to the PlantUML Server.
53              
54             Defaults to http://www.plantuml.com/plantuml
55              
56             =cut
57              
58             sub new {
59 1     1 1 247483 my $class = shift;
60 1         4 my $url = shift;
61             my %args = (
62 1   33     17 'baseurl' => $url || $ENV{PLANTUML_BASE_URL} || $URL,
63             'contexts' => ( 'png', 'svg', 'txt' ),
64             @_,
65             );
66              
67 1         10 return bless {%args}, $class;
68             }
69              
70             =head2 fetch_url
71              
72             First parameter is PlantUML Syntax as a String.
73              
74             Optionally second parameter is the format of the generated diagram as a String.
75              
76             Default is Text Format.
77              
78             =cut
79              
80             sub fetch_url {
81 1     1 1 6 my $self = shift;
82 1         7 my $base = $self->{'baseurl'};
83              
84 1         2 my $code = shift;
85 1         2 my $type = shift;
86              
87 1         6 my $ncoded = encode_p($code);
88 1 50       1770 my $url = defined $type ? "$base/$type/$ncoded" : "$base/txt/$ncoded";
89 1         7 return $url;
90             }
91              
92             =head1 AUTHOR
93              
94             Rangana Sudesha Withanage, C<< >>
95              
96             =head1 BUGS
97              
98             Please report any bugs or feature requests to C, or through
99             the web interface at L. I will be notified, and then you'll
100             automatically be notified of progress on your bug as I make changes.
101              
102              
103             =head1 SUPPORT
104              
105             You can find documentation for this module with the perldoc command.
106              
107             perldoc WWW::PlantUML
108              
109              
110             You can also look for information at:
111              
112             =over 4
113              
114             =item * RT: CPAN's request tracker (report bugs here)
115              
116             L
117              
118             =item * GitHub Repository
119              
120             L
121              
122             =item * CPAN Ratings
123              
124             L
125              
126             =item * Search CPAN
127              
128             L
129              
130             =back
131              
132              
133             =head1 ACKNOWLEDGEMENTS
134              
135             Author is inspired by the work of L, which was written by L.
136              
137             =head1 LICENSE AND COPYRIGHT
138              
139             This software is copyright (c) 2019 by Rangana Sudesha Withanage.
140              
141             This is free software; you can redistribute it and/or modify it under
142             the same terms as the Perl 5 programming language system itself.
143              
144              
145             =cut
146              
147             1; # End of WWW::PlantUML