| 1 | package UML::Sequence::SimpleSeq; | ||||||||||||||||||||||||||||
| 2 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 7 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | =head1 NAME | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | UML::Sequence::SimpleSeq - turns simple outlines (see below) into UML sequence diagrams | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | genericseq.pl UML::Sequence::SimpleSeq outline_file > sequence.xml | ||||||||||||||||||||||||||||
| 14 | seq2svg.pl sequence.xml > sequence.svg | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | OR | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | genericseq.pl UML::Sequence::SimpleSeq outline_file | seq2svg.pl > sequence.svg | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | OR | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | genericseq.pl UML::Sequence::SimpleSeq outline_file | seq2rast.pl > sequence.png | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | This file may be used directly by a script (as shown above) or as a base class | ||||||||||||||||||||||||||||
| 27 | for other sequencers (see UML::Sequence::JavaSeq). It supplies routines for | ||||||||||||||||||||||||||||
| 28 | handling simple outlines like a user could be expected to type by hand. Such | ||||||||||||||||||||||||||||
| 29 | outlines look like this: | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | At Home.Wash Car | ||||||||||||||||||||||||||||
| 32 | /* | ||||||||||||||||||||||||||||
| 33 | this is an annotation | ||||||||||||||||||||||||||||
| 34 | the next line shows how to specify return values | ||||||||||||||||||||||||||||
| 35 | */ | ||||||||||||||||||||||||||||
| 36 | Garage.retrieve bucket -> bucket | ||||||||||||||||||||||||||||
| 37 | Kitchen.prepare bucket | ||||||||||||||||||||||||||||
| 38 | Kitchen.pour soap in bucket | ||||||||||||||||||||||||||||
| 39 | Kitchen.fill bucket | ||||||||||||||||||||||||||||
| 40 | Garage.get sponge -> sponge | ||||||||||||||||||||||||||||
| 41 | /* | ||||||||||||||||||||||||||||
| 42 | the next line specifies an external async event | ||||||||||||||||||||||||||||
| 43 | */ | ||||||||||||||||||||||||||||
| 44 | -> clickerSignal | ||||||||||||||||||||||||||||
| 45 | /* | ||||||||||||||||||||||||||||
| 46 | the next line specifies a conditional, urgent method call | ||||||||||||||||||||||||||||
| 47 | */ | ||||||||||||||||||||||||||||
| 48 | [garageDoorClosed] ! Garage.open door | ||||||||||||||||||||||||||||
| 49 | /* | ||||||||||||||||||||||||||||
| 50 | the next line specifies an iterative method call | ||||||||||||||||||||||||||||
| 51 | */ | ||||||||||||||||||||||||||||
| 52 | * Driveway.apply soapy water | ||||||||||||||||||||||||||||
| 53 | Driveway.rinse | ||||||||||||||||||||||||||||
| 54 | Driveway.empty bucket | ||||||||||||||||||||||||||||
| 55 | -> clickerSignal | ||||||||||||||||||||||||||||
| 56 | Garage.close door | ||||||||||||||||||||||||||||
| 57 | Garage.replace sponge | ||||||||||||||||||||||||||||
| 58 | /* | ||||||||||||||||||||||||||||
| 59 | the next line specifies a class/static method call | ||||||||||||||||||||||||||||
| 60 | */ | ||||||||||||||||||||||||||||
| 61 | Garage::replace bucket | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | The "class" name and "method" name are separated by a dot. If there are | ||||||||||||||||||||||||||||
| 64 | multiple dots, the method name is everything after the last dot. Classes | ||||||||||||||||||||||||||||
| 65 | and methods in this context are elements of a UML sequence diagram. Classes | ||||||||||||||||||||||||||||
| 66 | get boxes at the top of the page. Method calls are labeled lines from one | ||||||||||||||||||||||||||||
| 67 | class to another. If you want two classes with the same name, you must | ||||||||||||||||||||||||||||
| 68 | append a suffix or prefix (try instanceName:ClassName). | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | Static (aka class) methods are assumed if there is not dot separator, but | ||||||||||||||||||||||||||||
| 71 | only double colon '::' separators, in which case the last text segment | ||||||||||||||||||||||||||||
| 72 | preceded by '::' is assumed to be the method name, and is displayed | ||||||||||||||||||||||||||||
| 73 | in italics in the output. | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | Return values may be specified by the '->' marker; everything to the | ||||||||||||||||||||||||||||
| 76 | right of the marker will be used as a label on a dashed line returning from | ||||||||||||||||||||||||||||
| 77 | the called object back to the caller object. | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | External events can be indicated by the '->' marker without any preceding | ||||||||||||||||||||||||||||
| 80 | object/method name. These are rendered as lines originating | ||||||||||||||||||||||||||||
| 81 | from the far right of the image, terminated by a half-arrow, with text to the | ||||||||||||||||||||||||||||
| 82 | right of the marker displayed as the label on a line. | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | Iterations are denoted by an introductory asterisk '*', which is preserved | ||||||||||||||||||||||||||||
| 85 | in the output label. Conditional statements can be added by introducing | ||||||||||||||||||||||||||||
| 86 | an entry with text enclosed by brackets '[]'. | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | For L<Thread::Apartment> applications, urgent methods are introduced | ||||||||||||||||||||||||||||
| 89 | by an exclamation point '!', which is preserved in the output text label. | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | Annotations may be specified using C style comment delimiters, | ||||||||||||||||||||||||||||
| 92 | '/* */'. Everything between the delimiters will be tagged as annotation on the next | ||||||||||||||||||||||||||||
| 93 | directive line, which the renderer may convert to e.g., tooltips | ||||||||||||||||||||||||||||
| 94 | or text in a margin. NOTE: no escape is provided for closing delimiters | ||||||||||||||||||||||||||||
| 95 | within an annotation. | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | Finally, in order to properly position return values for nested | ||||||||||||||||||||||||||||
| 98 | method calls, whitespace characters (tabs, spaces) are used to delimit | ||||||||||||||||||||||||||||
| 99 | the scope of nested method calls. | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =head1 grab_outline_text | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | Call this first with the outline file (in the format described above). | ||||||||||||||||||||||||||||
| 104 | Pass it the name of the file to read. | ||||||||||||||||||||||||||||
| 105 | Returns a reference to an array whose elements are lines from the outline | ||||||||||||||||||||||||||||
| 106 | with spacing preserved. | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | =cut | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 6 | ▶ | sub grab_outline_text { | ||||||||||||||||||||||||||
|
Subroutine
grab_outline_text: called CC=8 SCAR=21.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 111 | 6 | shift; # discard class | |||||||||||||||||||||||||||
| 112 | 6 | my $file = shift; | |||||||||||||||||||||||||||
| 113 | 6 | my @outline; | |||||||||||||||||||||||||||
| 114 | 6 | my $in_annot = undef; | |||||||||||||||||||||||||||
| 115 | 6 | my $annot = ''; | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 6 | ▶ | open FILE, "$file" or die "Couldn't open $file\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | 6 | ▶ | while (<FILE>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | # | ||||||||||||||||||||||||||||
| 120 | # aggregate annotations into a single line | ||||||||||||||||||||||||||||
| 121 | # NOTE: execution order is important to support single line annotations | ||||||||||||||||||||||||||||
| 122 | # NOTE2: trim leading tabs/spaces | ||||||||||||||||||||||||||||
| 123 | # | ||||||||||||||||||||||||||||
| 124 | 87 | chomp; | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 87 | ▶ | push(@outline, "$_ $annot"), | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$in_annot or m[^\s*/\*]
MC/DC50%1/2
$in_annot or m[^\s*/\*]
$in_annot
m[^\s*/\*]
Truth table66%2/3
A or B
A= $in_annotB= m[^\s*/\*]
| |||||||||||||||||||||||||||||
| 127 | $annot = '', | ||||||||||||||||||||||||||||
| 128 | next | ||||||||||||||||||||||||||||
| 129 | unless $in_annot || /^\s*\/\*/; | ||||||||||||||||||||||||||||
| 130 | # | ||||||||||||||||||||||||||||
| 131 | # in annotation, trim leading and trailing whitespace | ||||||||||||||||||||||||||||
| 132 | # | ||||||||||||||||||||||||||||
| 133 | 3 | s/^\s+//; | |||||||||||||||||||||||||||
| 134 | 3 | s/\s+$//; | |||||||||||||||||||||||||||
| 135 | 3 | ▶ | if ($in_annot) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 136 | 0 | $annot .= ' ' . $_; | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | elsif (/^\s*\/\*/) { | ||||||||||||||||||||||||||||
| 139 | 3 | $annot = $_; | |||||||||||||||||||||||||||
| 140 | 3 | $in_annot = 1; | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | $in_annot = undef | ||||||||||||||||||||||||||||
| 144 | 3 | ▶ | if /\*\/\s*$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | 6 | close FILE; | |||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | #print STDERR "\n\n", join("\n", @outline), "\n"; | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 6 | return \@outline; | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | =head1 grab_methods | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | Call this with an outline (possibly generated by grab_outline). It will return | ||||||||||||||||||||||||||||
| 156 | a hash reference. Each method mentioned in the outline will appear as a key | ||||||||||||||||||||||||||||
| 157 | in the hash (the values are less important, they count the occurances of | ||||||||||||||||||||||||||||
| 158 | the method). | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | =cut | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 16 | ▶ | sub grab_methods { | ||||||||||||||||||||||||||
|
Subroutine
grab_methods: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 163 | 16 | shift; # discard class | |||||||||||||||||||||||||||
| 164 | 16 | my $outline = shift; | |||||||||||||||||||||||||||
| 165 | 16 | my %methods; | |||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 16 | foreach (@$outline) { | |||||||||||||||||||||||||||
| 168 | 84 | my $line = $_; | |||||||||||||||||||||||||||
| 169 | 84 | $line =~ s/^\s+//; # trim leading space | |||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | # trim annotations | ||||||||||||||||||||||||||||
| 172 | 84 | $line=~s/\s*\/\*.*\*\/\s*$//; | |||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 84 | ▶ | next if ($line=~/^\s*$/); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 84 | $line =~ s/^[^:]+://; # trim class info | |||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | # trim leading iterator, conditionals, or urgents | ||||||||||||||||||||||||||||
| 179 | 84 | $line =~ s/^(((\[[^\]]+\])|[\*!])\s*)+//; | |||||||||||||||||||||||||||
| 180 | # | ||||||||||||||||||||||||||||
| 181 | # trim any following returnvalue list | ||||||||||||||||||||||||||||
| 182 | # | ||||||||||||||||||||||||||||
| 183 | 84 | $line =~ s/\s*->.*$//; | |||||||||||||||||||||||||||
| 184 | 84 | ▶ | $line = 'EXTERNAL' if ($line eq ''); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 185 | 84 | $methods{$line}++; | |||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | 16 | return \%methods; | |||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | =head1 parse_signature | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | This method is a call back used by the UML::Sequence constructor. It accepts | ||||||||||||||||||||||||||||
| 193 | a signature and returns the "class" name (in scalar context) or, in list context, | ||||||||||||||||||||||||||||
| 194 | the "class", "method", "returnvalue", iterator, urgent, conditional, indicators, | ||||||||||||||||||||||||||||
| 195 | and any annotation. It splits the signature on the | ||||||||||||||||||||||||||||
| 196 | last dot it sees after removing any argument list and associated parentheses. | ||||||||||||||||||||||||||||
| 197 | It also looks for the '->' marker in order to collect a return values list. | ||||||||||||||||||||||||||||
| 198 | NOTE: BE SURE TO PRESERVE INTRO WHITESPACE FOR NESTED METHOD SCOPING!! | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | =cut | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 29 | ▶ | sub parse_signature { | ||||||||||||||||||||||||||
|
Subroutine
parse_signature: called CC=10 SCAR=27.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 203 | 29 | chomp(my $line = shift); | |||||||||||||||||||||||||||
| 204 | # | ||||||||||||||||||||||||||||
| 205 | # external event: add External class to list, and collect | ||||||||||||||||||||||||||||
| 206 | # rest of the line as event label | ||||||||||||||||||||||||||||
| 207 | # | ||||||||||||||||||||||||||||
| 208 | #print STDERR $line, "\n"; | ||||||||||||||||||||||||||||
| 209 | 29 | ▶ | return wantarray ? ('_EXTERNAL', $1) : '_EXTERNAL' | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 210 | if ($line=~/^\s*->\s*(.+)$/); | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 29 | my ($iterator, $conditional, $urgent, $annot); | |||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 29 | ▶ | $annot = $1 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 215 | if ($line =~ s/\s*\/\*\s*(.*)\s*\*\/\s*$//); | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | 29 | ▶ | while ($line =~ s/^((\[[^\]]+\])|[\*!])\s*//) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 218 | 0 | ▶ | $iterator = '*', next | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 219 | if ($1 eq '*'); | ||||||||||||||||||||||||||||
| 220 | 0 | ▶ | $urgent = '!', next | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 221 | if ($1 eq '!'); | ||||||||||||||||||||||||||||
| 222 | 0 | $conditional = $1; | |||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | 29 | $line =~ s/\(.*\)//; # rely on greedy eval...tho I may decide to include the args | |||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 29 | my $returns; | |||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | 29 | ▶ | $returns = $1 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 230 | if ($line=~s/->\s*(.*)$//); | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | 29 | $line =~ s/[\.:]([^\.:]*)\s*$//; | |||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | 29 | my $method = $1; | |||||||||||||||||||||||||||
| 235 | 29 | ▶ | if (defined $method) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | 28 | $method =~ s/</</g; | |||||||||||||||||||||||||||
| 237 | 28 | $method =~ s/>/>/g; | |||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||
| 239 | return wantarray ? | ||||||||||||||||||||||||||||
| 240 | 29 | ▶ | ($line, $method, $returns, $iterator, $urgent, $conditional, $annot) : | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 241 | $line; | ||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | 7 | 1; | |||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | =head1 AUTHORS | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | Original versions by Phil Crow, <philcrow2000@yahoo.com> | ||||||||||||||||||||||||||||
| 249 | Version 0.02 by Dean Arnold, <darnold@presicient.com> | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | Copyright 2003-2006, Philip Crow, all rights reserved. | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | You may modify and/or redistribute this code in the same manner as Perl itself. | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | =cut | ||||||||||||||||||||||||||||