line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::WebSequenceDiagrams; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
39
|
|
5
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
75
|
|
6
|
1
|
|
|
1
|
|
382
|
use WebService::Simple; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use base qw( Class::Accessor::Fast ); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors($_) |
10
|
|
|
|
|
|
|
for qw(wsd message style paginate paper landscape format outfile tab); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.00001'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
|
|
|
|
|
|
my $class = shift; |
16
|
|
|
|
|
|
|
my $self = bless { |
17
|
|
|
|
|
|
|
style => 'default', |
18
|
|
|
|
|
|
|
paginate => 1, |
19
|
|
|
|
|
|
|
paper => 'letter', |
20
|
|
|
|
|
|
|
landscape => 1, |
21
|
|
|
|
|
|
|
format => 'png', |
22
|
|
|
|
|
|
|
@_ |
23
|
|
|
|
|
|
|
}, $class; |
24
|
|
|
|
|
|
|
$self->_init; |
25
|
|
|
|
|
|
|
return $self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _init { |
29
|
|
|
|
|
|
|
my $self = shift; |
30
|
|
|
|
|
|
|
if ( !$self->wsd ) { |
31
|
|
|
|
|
|
|
$self->wsd( |
32
|
|
|
|
|
|
|
WebService::Simple->new( |
33
|
|
|
|
|
|
|
base_url => 'http://www.websequencediagrams.com/' |
34
|
|
|
|
|
|
|
) |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
if ( !$self->tab ) { |
38
|
|
|
|
|
|
|
$self->tab(0); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub draw { |
43
|
|
|
|
|
|
|
my $self = shift; |
44
|
|
|
|
|
|
|
my %args = @_; |
45
|
|
|
|
|
|
|
my $style = $args{style} || $self->style; |
46
|
|
|
|
|
|
|
my $message = $args{message} || $self->message; |
47
|
|
|
|
|
|
|
my $paginate = $args{paginate} || $self->paginate; |
48
|
|
|
|
|
|
|
my $paper = $args{paper} || $self->paper; |
49
|
|
|
|
|
|
|
my $landscape = $args{landscape} || $self->landscape; |
50
|
|
|
|
|
|
|
my $format = $args{format} || $self->format; |
51
|
|
|
|
|
|
|
my $outfile = $args{outfile}; |
52
|
|
|
|
|
|
|
if ( !$outfile ) { |
53
|
|
|
|
|
|
|
croak("you have to pass an outfile to draw() method"); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
my $res = $self->wsd->get( |
56
|
|
|
|
|
|
|
{ |
57
|
|
|
|
|
|
|
style => $style, |
58
|
|
|
|
|
|
|
message => $message, |
59
|
|
|
|
|
|
|
paginate => $paginate, |
60
|
|
|
|
|
|
|
paper => $paper, |
61
|
|
|
|
|
|
|
landscape => $landscape, |
62
|
|
|
|
|
|
|
format => $format, |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
); |
65
|
|
|
|
|
|
|
$self->_save( $res, $outfile ); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub _save { |
69
|
|
|
|
|
|
|
my $self = shift; |
70
|
|
|
|
|
|
|
my $res = shift; |
71
|
|
|
|
|
|
|
my $outfile = shift; |
72
|
|
|
|
|
|
|
open( FILE, ">", $outfile ); |
73
|
|
|
|
|
|
|
flock( FILE, 2 ); |
74
|
|
|
|
|
|
|
binmode(FILE); |
75
|
|
|
|
|
|
|
print FILE $res->content; |
76
|
|
|
|
|
|
|
flock( FILE, 8 ); |
77
|
|
|
|
|
|
|
close(FILE); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub _push_tab { |
81
|
|
|
|
|
|
|
my $self = shift; |
82
|
|
|
|
|
|
|
my $message_ref = shift; |
83
|
|
|
|
|
|
|
if ( $self->tab > 0 ) { |
84
|
|
|
|
|
|
|
for ( 1 .. $self->tab ) { |
85
|
|
|
|
|
|
|
$$message_ref .= "\t"; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub participant { |
91
|
|
|
|
|
|
|
my $self = shift; |
92
|
|
|
|
|
|
|
my %args = @_; |
93
|
|
|
|
|
|
|
my $message = $self->message; |
94
|
|
|
|
|
|
|
$self->_push_tab( \$message ); |
95
|
|
|
|
|
|
|
$message .= 'participant "' . $args{name} . '"'; |
96
|
|
|
|
|
|
|
if ( $args{as} ) { |
97
|
|
|
|
|
|
|
$message .= ' as ' . $args{as}; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
$message .= "\n"; |
100
|
|
|
|
|
|
|
$self->message($message); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub signal { |
104
|
|
|
|
|
|
|
my $self = shift; |
105
|
|
|
|
|
|
|
my %args = @_; |
106
|
|
|
|
|
|
|
my $line = ( $args{line} and $args{line} eq 'broken' ) ? '-->' : '->'; |
107
|
|
|
|
|
|
|
my $message = $self->message; |
108
|
|
|
|
|
|
|
$self->_push_tab( \$message ); |
109
|
|
|
|
|
|
|
$message .= $args{from} . $line . $args{to} . ': ' . $args{text}; |
110
|
|
|
|
|
|
|
$message .= "\n"; |
111
|
|
|
|
|
|
|
$self->message($message); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub signal_to_self { |
115
|
|
|
|
|
|
|
my $self = shift; |
116
|
|
|
|
|
|
|
my %args = @_; |
117
|
|
|
|
|
|
|
$self->signal( %args, from => $args{itself}, to => $args{itself} ); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub alt { |
121
|
|
|
|
|
|
|
my $self = shift; |
122
|
|
|
|
|
|
|
my %args = @_; |
123
|
|
|
|
|
|
|
$args{text} ||= ''; |
124
|
|
|
|
|
|
|
my $message = $self->message; |
125
|
|
|
|
|
|
|
$self->_push_tab( \$message ); |
126
|
|
|
|
|
|
|
$message .= 'alt ' . $args{text}; |
127
|
|
|
|
|
|
|
$message .= "\n"; |
128
|
|
|
|
|
|
|
$self->message($message); |
129
|
|
|
|
|
|
|
$self->tab( $self->tab + 1 ); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub else { |
133
|
|
|
|
|
|
|
my $self = shift; |
134
|
|
|
|
|
|
|
my %args = @_; |
135
|
|
|
|
|
|
|
$args{text} ||= ''; |
136
|
|
|
|
|
|
|
$self->tab( $self->tab - 1 ); |
137
|
|
|
|
|
|
|
my $message = $self->message; |
138
|
|
|
|
|
|
|
$self->_push_tab( \$message ); |
139
|
|
|
|
|
|
|
$message .= 'else ' . $args{text}; |
140
|
|
|
|
|
|
|
$message .= "\n"; |
141
|
|
|
|
|
|
|
$self->message($message); |
142
|
|
|
|
|
|
|
$self->tab( $self->tab + 1 ); |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub opt { |
146
|
|
|
|
|
|
|
my $self = shift; |
147
|
|
|
|
|
|
|
my %args = @_; |
148
|
|
|
|
|
|
|
$args{text} ||= ''; |
149
|
|
|
|
|
|
|
my $message = $self->message; |
150
|
|
|
|
|
|
|
$self->_push_tab( \$message ); |
151
|
|
|
|
|
|
|
$message .= 'opt ' . $args{text}; |
152
|
|
|
|
|
|
|
$message .= "\n"; |
153
|
|
|
|
|
|
|
$self->message($message); |
154
|
|
|
|
|
|
|
$self->tab( $self->tab + 1 ); |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub loop { |
158
|
|
|
|
|
|
|
my $self = shift; |
159
|
|
|
|
|
|
|
my %args = @_; |
160
|
|
|
|
|
|
|
$args{text} ||= ''; |
161
|
|
|
|
|
|
|
my $message = $self->message; |
162
|
|
|
|
|
|
|
$self->_push_tab( \$message ); |
163
|
|
|
|
|
|
|
$message .= 'loop ' . $args{text}; |
164
|
|
|
|
|
|
|
$message .= "\n"; |
165
|
|
|
|
|
|
|
$self->message($message); |
166
|
|
|
|
|
|
|
$self->tab( $self->tab + 1 ); |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub end { |
170
|
|
|
|
|
|
|
my $self = shift; |
171
|
|
|
|
|
|
|
my %args = @_; |
172
|
|
|
|
|
|
|
$args{text} ||= ''; |
173
|
|
|
|
|
|
|
$self->tab( $self->tab - 1 ); |
174
|
|
|
|
|
|
|
my $message = $self->message; |
175
|
|
|
|
|
|
|
$self->_push_tab( \$message ); |
176
|
|
|
|
|
|
|
$message .= 'end'; |
177
|
|
|
|
|
|
|
$message .= "\n"; |
178
|
|
|
|
|
|
|
$self->message($message); |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub note { |
182
|
|
|
|
|
|
|
my $self = shift; |
183
|
|
|
|
|
|
|
my %args = @_; |
184
|
|
|
|
|
|
|
my $pos; |
185
|
|
|
|
|
|
|
if ( $args{position} eq 'left_of' ) { |
186
|
|
|
|
|
|
|
$pos = 'left of '; |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
elsif ( $args{position} eq 'right_of' ) { |
189
|
|
|
|
|
|
|
$pos = 'right of '; |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
else { |
192
|
|
|
|
|
|
|
$pos = 'over '; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
my $message = $self->message; |
195
|
|
|
|
|
|
|
$self->_push_tab( \$message ); |
196
|
|
|
|
|
|
|
$message .= 'note ' . $pos; |
197
|
|
|
|
|
|
|
if ( ref $args{name} eq 'ARRAY' ) { |
198
|
|
|
|
|
|
|
$message .= join( ',', @{ $args{name} } ); |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
else { |
201
|
|
|
|
|
|
|
$message .= $args{name}; |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
if ( $args{text} =~ "\n" ) { |
204
|
|
|
|
|
|
|
$message .= "\n"; |
205
|
|
|
|
|
|
|
for ( split( /\n/, $args{text} ) ) { |
206
|
|
|
|
|
|
|
$message .= "\t" . $_ . "\n"; |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
$message .= 'end note' . "\n"; |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
else { |
211
|
|
|
|
|
|
|
$message .= ': ' . $args{text} . "\n"; |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
$self->message($message); |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
sub activate { |
217
|
|
|
|
|
|
|
my $self = shift; |
218
|
|
|
|
|
|
|
my $name = shift; |
219
|
|
|
|
|
|
|
my $message = $self->message; |
220
|
|
|
|
|
|
|
$self->_push_tab( \$message ); |
221
|
|
|
|
|
|
|
$message .= 'activate ' . $name . "\n"; |
222
|
|
|
|
|
|
|
$self->message($message); |
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
sub destroy { |
226
|
|
|
|
|
|
|
my $self = shift; |
227
|
|
|
|
|
|
|
my $name = shift; |
228
|
|
|
|
|
|
|
my $message = $self->message; |
229
|
|
|
|
|
|
|
$self->_push_tab( \$message ); |
230
|
|
|
|
|
|
|
$message .= 'destroy ' . $name . "\n"; |
231
|
|
|
|
|
|
|
$self->message($message); |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
sub deactivate { |
235
|
|
|
|
|
|
|
my $self = shift; |
236
|
|
|
|
|
|
|
my $name = shift; |
237
|
|
|
|
|
|
|
my $message = $self->message; |
238
|
|
|
|
|
|
|
$self->_push_tab( \$message ); |
239
|
|
|
|
|
|
|
$message .= 'deactivate ' . $name . "\n"; |
240
|
|
|
|
|
|
|
$self->message($message); |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
1; |
244
|
|
|
|
|
|
|
__END__ |