line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package UML::PlantUML::Encoder; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
131701
|
use 5.006; |
|
2
|
|
|
|
|
14
|
|
4
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
51
|
|
5
|
2
|
|
|
2
|
|
21
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
81
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
1425
|
use Encode qw(encode); |
|
2
|
|
|
|
|
30826
|
|
|
2
|
|
|
|
|
136
|
|
8
|
2
|
|
|
2
|
|
1239
|
use Compress::Zlib; |
|
2
|
|
|
|
|
124422
|
|
|
2
|
|
|
|
|
448
|
|
9
|
2
|
|
|
2
|
|
1013
|
use MIME::Base64; |
|
2
|
|
|
|
|
1284
|
|
|
2
|
|
|
|
|
208
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our ( @ISA, @EXPORT, @EXPORT_OK ); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
BEGIN { |
14
|
2
|
|
|
2
|
|
15
|
require Exporter; |
15
|
2
|
|
|
|
|
35
|
@ISA = qw(Exporter); |
16
|
2
|
|
|
|
|
9
|
@EXPORT = qw(encode_p); # symbols to export |
17
|
2
|
|
|
|
|
1182
|
@EXPORT_OK = qw(encode_p); # symbols to export on request |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 NAME |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
UML::PlantUML::Encoder - Provides PlantUML Language's Encoding in Perl |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Encodes PlantUML Diagram Text using the PlantUML Encoding Standard described at L |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 VERSION |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Version 0.02 |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 SYNOPSIS |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
use UML::PlantUML::Encoder qw(encode_p); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $encoded = encode_p(qq{ |
39
|
|
|
|
|
|
|
Alice -> Bob: Authentication Request |
40
|
|
|
|
|
|
|
Bob --> Alice: Authentication Response |
41
|
|
|
|
|
|
|
}); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
print "http://www.plantuml.com/plantuml/uml/$encoded"; |
44
|
|
|
|
|
|
|
print "http://www.plantuml.com/plantuml/png/$encoded"; |
45
|
|
|
|
|
|
|
print "http://www.plantuml.com/plantuml/svg/$encoded"; |
46
|
|
|
|
|
|
|
print "http://www.plantuml.com/plantuml/txt/$encoded"; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 EXPORT |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
The only Subroutine that this module exports is C |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head2 utf8_encode |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Encoded in UTF-8 |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub utf8_encode { |
61
|
1
|
|
|
1
|
1
|
10
|
return encode( 'UTF-8', $_[0] ); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 _compress_with_deflate |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Compressed using Deflate algorithm |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub _compress_with_deflate { |
71
|
1
|
|
|
1
|
|
3
|
my $buffer; |
72
|
1
|
|
|
|
|
4
|
my $d = deflateInit( -WindowBits => $_[1] ); |
73
|
1
|
|
|
|
|
538
|
$buffer = $d->deflate( $_[0] ); |
74
|
1
|
|
|
|
|
22
|
$buffer .= $d->flush(); |
75
|
1
|
|
|
|
|
143
|
return $buffer; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 encode6bit |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Transform to String of characters that contains only digits, letters, underscore and minus character |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub encode6bit { |
85
|
84
|
|
|
84
|
1
|
146
|
my $b = $_[0]; |
86
|
84
|
100
|
|
|
|
157
|
if ( $b < 10 ) { |
87
|
16
|
|
|
|
|
33
|
return chr( 48 + $b ); |
88
|
|
|
|
|
|
|
} |
89
|
68
|
|
|
|
|
78
|
$b -= 10; |
90
|
68
|
100
|
|
|
|
113
|
if ( $b < 26 ) { |
91
|
41
|
|
|
|
|
80
|
return chr( 65 + $b ); |
92
|
|
|
|
|
|
|
} |
93
|
27
|
|
|
|
|
33
|
$b -= 26; |
94
|
27
|
50
|
|
|
|
42
|
if ( $b < 26 ) { |
95
|
27
|
|
|
|
|
84
|
return chr( 97 + $b ); |
96
|
|
|
|
|
|
|
} |
97
|
0
|
|
|
|
|
0
|
$b -= 26; |
98
|
0
|
0
|
|
|
|
0
|
if ( $b == 0 ) { |
99
|
0
|
|
|
|
|
0
|
return '-'; |
100
|
|
|
|
|
|
|
} |
101
|
0
|
0
|
|
|
|
0
|
if ( $b == 1 ) { |
102
|
0
|
|
|
|
|
0
|
return '_'; |
103
|
|
|
|
|
|
|
} |
104
|
0
|
|
|
|
|
0
|
return '?'; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head2 append3bytes |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Transform adjacent bytes |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=cut |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub append3bytes { |
114
|
21
|
|
|
21
|
1
|
26
|
my ( $c1, $c2, $c3, $c4, $r ); |
115
|
21
|
|
|
|
|
31
|
my $b1 = $_[0]; |
116
|
21
|
|
|
|
|
27
|
my $b2 = $_[1]; |
117
|
21
|
|
|
|
|
25
|
my $b3 = $_[2]; |
118
|
21
|
|
|
|
|
26
|
$c1 = $b1 >> 2; |
119
|
21
|
|
|
|
|
35
|
$c2 = ( ( $b1 & 0x3 ) << 4 ) | ( $b2 >> 4 ); |
120
|
21
|
|
|
|
|
31
|
$c3 = ( ( $b2 & 0xF ) << 2 ) | ( $b3 >> 6 ); |
121
|
21
|
|
|
|
|
25
|
$c4 = $b3 & 0x3F; |
122
|
21
|
|
|
|
|
31
|
$r = ""; |
123
|
21
|
|
|
|
|
31
|
$r .= encode6bit( $c1 & 0x3F ); |
124
|
21
|
|
|
|
|
39
|
$r .= encode6bit( $c2 & 0x3F ); |
125
|
21
|
|
|
|
|
39
|
$r .= encode6bit( $c3 & 0x3F ); |
126
|
21
|
|
|
|
|
36
|
$r .= encode6bit( $c4 & 0x3F ); |
127
|
21
|
|
|
|
|
58
|
return $r; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head2 encode64 |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Reencoded in ASCII using a transformation close to base64 |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=cut |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub encode64 { |
137
|
1
|
|
|
1
|
1
|
3
|
my $c = $_[0]; |
138
|
1
|
|
|
|
|
2
|
my $str = ""; |
139
|
1
|
|
|
|
|
3
|
my $len = length $c; |
140
|
1
|
|
|
|
|
14
|
my $i; |
141
|
1
|
|
|
|
|
6
|
for ( $i = 0; $i < $len; $i += 3 ) { |
142
|
21
|
50
|
|
|
|
48
|
if ( $i + 2 == $len ) { |
|
|
50
|
|
|
|
|
|
143
|
0
|
|
|
|
|
0
|
$str .= append3bytes( ord( substr( $c, $i, 1 ) ), |
144
|
|
|
|
|
|
|
ord( substr( $c, $i + 1, 1 ) ), 0 ); |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
elsif ( $i + 1 == $len ) { |
147
|
0
|
|
|
|
|
0
|
$str .= append3bytes( ord( substr( $c, $i, 1 ) ), 0, 0 ); |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
else { |
150
|
21
|
|
|
|
|
51
|
$str .= append3bytes( |
151
|
|
|
|
|
|
|
ord( substr( $c, $i, 1 ) ), |
152
|
|
|
|
|
|
|
ord( substr( $c, $i + 1, 1 ) ), |
153
|
|
|
|
|
|
|
ord( substr( $c, $i + 2, 1 ) ) |
154
|
|
|
|
|
|
|
); |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
} |
157
|
1
|
|
|
|
|
11
|
return $str; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head2 encode_p |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Encodes diagram text descriptions |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=cut |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub encode_p { |
167
|
1
|
|
|
1
|
1
|
840
|
my $data = utf8_encode( $_[0] ); |
168
|
1
|
|
|
|
|
220
|
my $compressed = _compress_with_deflate( $data, 9 ); |
169
|
1
|
|
|
|
|
6
|
return encode64($compressed); |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 AUTHOR |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Rangana Sudesha Withanage, C<< >> |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head1 BUGS |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
179
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
180
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 SUPPORT |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
perldoc UML::PlantUML::Encoder |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
You can also look for information at: |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=over 4 |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
L |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
L |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=item * CPAN Ratings |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
L |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=item * Search CPAN |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
L |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=back |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
This software is copyright (c) 2019 by Rangana Sudesha Withanage. |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
220
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=cut |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
1; # End of UML::PlantUML::Encoder |