blib/lib/Asterisk/config/syntax/highlight.pm

filter: Statementstmt 19.5% 17 / 87 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 25.0% 4 / 16 Podpod 62.5% 5 / 8 totaltotal 19.8% 26 / 131 CC 8 SCAR 26.1
CC
8
Cov
17%
_make_map
42.0
load_file
12.0
new
2.0
CRAP 13.6
↑ Summary
1 package Asterisk::config::syntax::highlight;
2 1 ▶use strict "vars";
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Syntax::Highlight::Engine::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 our $strict;
5 1 our $VERSION = '0.5';
6  
7 1 ▶use Class::Std::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 {
9 1 my %global;
10  
11 0 ▶ sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
12 0 my ($class) = @_;
13 0 my $self = bless \do { my $anon_scalar }, $class;
14 0 return $self;
15 }
16  
17 0 ▶ sub load_file {
Subroutine load_file: not called CC=3 SCAR=24.8
Pod documented
18 0 my ( $self, %options ) = @_;
19 0 ▶ $strict = $options{strict} || 0;
Condition0%0/2
$options{'strict'} || 0
l!l
00
MC/DC0%0/1
$options{'strict'} || 0
$options{'strict'}
Truth table0%0/2
A
A= $options{'strict'}
Aresult
11
00
20  
21 0 my $highlight = Syntax::Highlight::Engine::Simple->new();
22 0 $highlight->setSyntax(
23 syntax => [
24 {
25 class => 'identifier',
26 regexp => "\[(.*)\]",
27 },
28 {
29 class => 'exten',
30 regexp => qr!\\;!,
31 },
32 {
33 class => 'value',
34 regexp => "\[{.*}\]",
35 },
36 {
37 class => 'comment',
38 regexp => "\;(.*)",
39 },
40 {
41 class => 'exten',
42 regexp => q!(\s*)\[(.*)\]!,
43 },
44 {
45 class => 'exten',
46 regexp => q!include(\s*)(=|=>)(.*)!,
47 },
48 {
49 class => 'exten',
50 regexp => $highlight->array2regexp( exten() ),
51 },
52 {
53 class => 'keyword',
54 regexp => $highlight->array2regexp( commands() ),
55  
56 },
57 {
58 class => 'function',
59 regexp => $highlight->array2regexp( functions() ),
60  
61 },
62 ]
63 );
64  
65 0 ▶ open my $in, '<', $options{file} or die 'not that file?';
Branch: 1 branch
BranchTrueFalseTotal
open my $in, "<", $options{"file"} or die "not that file?" 0 0 0
66 0 my $datas = do { local $/; <$in> };
67 0 close $in;
68 0 $/ = "\n";
69  
70 my @data =
71 0 map { $highlight->doStr( str => $_ ) }
72 split( /\n/, $datas );
73 0 $global{ ident $self}{datas} = \@data;
74  
75 }
76  
77 #only return array references now
78 0 ▶ sub return_html_array_ref {
Subroutine return_html_array_ref: not called CC=1 SCAR=6.9
Pod documented
79 0 my ( $self, %options ) = @_;
80 0 return $global{ ident $self}{datas};
81 }
82  
83 0 ▶ sub return_ubb_array_ref {
Subroutine return_ubb_array_ref: not called CC=1 SCAR=6.9
Pod documented
84 0 my ( $self, %options ) = @_;
85 my @data =
86 0 map { $self->_html2ubb($_); } @{ $global{ ident $self}{datas} };
87 0 return \@data;
88  
89 }
90  
91 0 ▶ sub return_wiki_array_ref {
Subroutine return_wiki_array_ref: not called CC=1 SCAR=6.9
Pod documented
92 0 my ( $self, %options ) = @_;
93 my @data =
94 0 map { $self->_html2wiki($_); } @{ $global{ ident $self}{datas} };
95 0 return \@data;
96 }
97  
98 0 ▶ sub _html2ubb {
Subroutine _html2ubb: not called CC=1 SCAR=6.9
99 0 my ( $self, $text ) = @_;
100 0 $text =~ s/<span(\s)class='keyword'>/[color=blue]/ig;
101 0 $text =~ s/<span(\s)class='function'>/[color=olive]/ig;
102 0 $text =~ s/<span(\s)class='comment'>/[color=seagreen]/ig;
103 0 $text =~ s/<span(\s)class='value'>/[color=purple]/ig;
104 0 $text =~ s/<span(\s)class='identifier'>/[color=magenta]/ig;
105 0 $text =~ s/<span(\s)class='exten'>/[color=red]/ig;
106 0 $text =~ s/<\/span>/[\/color]/ig;
107 0 return $text;
108 }
109  
110 0 ▶ sub _html2wiki {
Subroutine _html2wiki: not called CC=1 SCAR=6.9
111 0 my ( $self, $text ) = @_;
112 0 $text =~ s/<span(\s)class='keyword'>/~~blue:/ig;
113 0 $text =~ s/<span(\s)class='function'>/~~olive:/ig;
114 0 $text =~ s/<span(\s)class='comment'>/~~seagreen:/ig;
115 0 $text =~ s/<span(\s)class='value'>/~~purple:/ig;
116 0 $text =~ s/<span(\s)class='identifier'>/~~magenta:/ig;
117 0 $text =~ s/<span(\s)class='exten'>/~~red:/ig;
118 0 $text =~ s/<\/span>/~~/ig;
119 0 $text =~ s/\[/\[\[/ig;
120 0 return $text;
121 }
122  
123 0 ▶ sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=6.9
124 0 my ($self) = @_;
125 0 delete $global{ ident $self};
126 0 return;
127 }
128  
129 0 ▶ sub commands {
Subroutine commands: not called CC=1 SCAR=6.9
Pod undocumented
130 0 return qw/
131 AbsoluteTimeout
132 AddQueueMember
133 ADSIProg
134 AgentCallbackLogin
135 AgentLogin
136 AgentMonitorOutgoing
137 AGI
138 AlarmReceiver
139 ALSAMonitor
140 AMD
141 Answer
142 AppendCDRUserField
143 Authenticate
144 BackGround
145 BackgroundDetect
146 Bridge
147 Busy
148 CallingPres
149 ChangeMonitor
150 ChanIsAvail
151 ChannelRedirect
152 ChanSpy
153 CheckGroup
154 ClearHash
155 Congestion
156 ContinueWhile
157 ControlPlayback
158 DAHDIBarge
159 DAHDIRAS
160 DAHDIScan
161 DAHDISendKeypadFacility
162 DBdel
163 DBdeltree
164 DBQuery
165 DBRewrite
166 DeadAGI
167 Dial
168 Dictate
169 DigitTimeout
170 Directory
171 DISA
172 DTMFToText
173 DUNDiLookup
174 EAGI
175 Echo
176 EndWhile
177 EnumLookup
178 Exec
179 ExecIf
180 ExecIfTime
181 ExitWhile
182 ExtenSpy
183 ExternIVR
184 Festival
185 Flash
186 Flite
187 ForkCDR
188 GetCPEID
189 GetGroupCount
190 GetGroupMatchCount
191 Gosub
192 GosubIf
193 Goto
194 GotoIf
195 GotoIfTime
196 Hangup
197 HasNewVoicemail
198 HasVoicemail
199 ICES
200 ImportVar
201 JabberSend
202 JabberStatus
203 KeepAlive
204 Log
205 LookupBlacklist
206 LookupCIDName
207 Macro
208 MacroExclusive
209 MacroExit
210 MailboxExists
211 MeetMe
212 MeetMeAdmin
213 MeetMeChannelAdmin
214 MeetMeCount
215 Milliwatt
216 MiniVM
217 MixMonitor
218 Monitor
219 MP3Player
220 MSet
221 MusicOnHold
222 MYSQL
223 Asterisk cmg NBScat
224 NoCDR
225 NoOp
226 ODBCFinish
227 Page
228 Park
229 ParkAndAnnounce
230 ParkedCall
231 PauseQueueMember
232 Perl
233 Pickup
234 PickUP
235 PickupChan
236 Playback
237 Playtones
238 PPPD
239 PrivacyManager
240 Proceeding
241 Progress
242 Queue
243 Random
244 Read
245 ReadExten
246 ReadFile
247 RealTime
248 Record
249 RemoveQueueMember
250 ResetCDR
251 ResponseTimeout
252 RetryDial
253 Return
254 Ringing
255 Rpt
256 SayAlpha
257 SayDigits
258 SayNumber
259 SayPhonetic
260 SayUnixTime
261 SendDTMF
262 SendImage
263 SendText
264 SendURL
265 Set
266 SetAccount
267 SetAMAflags
268 SetCallerID
269 SetCallerPres
270 SetCDRUserField
271 SetGlobalVar
272 SetMusicOnHold
273 SIPAddHeader
274 SIPCallPickup
275 SIPGetHeader
276 SIPdtmfMode
277 SMS
278 SoftHangup
279 SrxEchoCan
280 SrxDeflect
281 SrxMWI
282 StackPop
283 Steal
284 StopMonitor
285 StopMixMonitor
286 StopPlaytones
287 System
288 TestClient
289 TestServer
290 Transfer
291 TrySystem
292 TXTCIDName
293 UnpauseQueueMember
294 UserEvent
295 VMAuthenticate
296 VoiceMail
297 VoiceMailMain
298 Wait
299 WaitExten
300 WaitForRing
301 WaitMusicOnHold
302 WaitUntil
303 While
304 Zapateller
305 /;
306 }
307  
308 0 ▶ sub functions {
Subroutine functions: not called CC=1 SCAR=6.9
Pod undocumented
309 0 return qw/
310 AGENT
311 ARRAY
312 BASE64_DECODE
313 BASE64_ENCODE
314 CALLERID
315 CDR
316 CHANNEL
317 CHECKSIPDOMAIN
318 CHECK_MD5
319 clearhash
320 CURL
321 CUT
322 device_State
323 DB
324 DB_DELETE
325 DB_EXISTS
326 DIALGROUP
327 dialplan_exists
328 DUNDILOOKUP
329 ENUMLOOKUP
330 ENV
331 EVAL
332 EXISTS
333 extension_state
334 FIELDQTY
335 FILTER
336 GROUP
337 GROUP_COUNT
338 GROUP_LIST
339 GROUP_MATCH_COUNT
340 HASH
341 hashkeys
342 hint
343 IAXPEER
344 iaxvar
345 IF
346 IFTIME
347 ISNULL
348 KEYPADHASH
349 LANGUAGE
350 LEN
351 MATH
352 MD5
353 MUSICCLASS
354 ODBC
355 QUEUEAGENTCOUNT
356 QUEUE_MEMBER_COUNT
357 QUEUE_MEMBER_LIST
358 QUOTE
359 RAND
360 REALTIME
361 REGEX
362 SET
363 SHA1
364 SHARED
365 SIPCHANINFO
366 SIPPEER
367 SIPAddHeader
368 SIP_HEADER
369 SORT
370 SQL_ESC
371 STAT
372 STRFTIME
373 STRPTIME
374 sysinfo
375 TIMEOUT
376 toupper
377 tolower
378 TXTCIDNAME
379 URIDECODE
380 URIENCODE
381 VOLUME
382 VMCOUNT
383 /;
384 }
385  
386 0 ▶ sub exten {
Subroutine exten: not called CC=1 SCAR=6.9
Pod undocumented
387 0 return qw/
388 exten
389 /;
390 }
391  
392 1 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
393  
394 #reload
395 0 ▶ sub Syntax::Highlight::Engine::Simple::_make_map {
Subroutine _make_map: not called CC=6 SCAR=37.4
396  
397 0 my $self = shift;
398 0 my %args = ( str => '', pos => 0, index => undef, @_ );
399  
400 0 my $map_ref = $self->{_markup_map};
401 0 my @scraps;
402 0 ▶ if ($strict) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Asterisk::config::syntax::highlight::strict) { } 0 0 0
403 @scraps =
404 split( /$self->{syntax}->[$args{index}]->{regexp}/,
405 0 $args{str}, 2 );
406 }
407 else {
408 @scraps =
409 split( /$self->{syntax}->[$args{index}]->{regexp}/i,
410 0 $args{str}, 2 );
411 }
412  
413 0 ▶ if ( ( scalar @scraps ) >= 2 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @scraps >= 2) { } 0 0 0
elsif (@$map_ref) { } 0 0 0
414  
415 0 my $rest = pop(@scraps);
416 0 my $ins_pos0 = $args{pos} + length( $scraps[0] );
417 my $ins_pos1 =
418 0 $args{pos} + ( length( $args{str} ) - length($rest) );
419  
420 ### Add markup position
421 0 push( @$map_ref, [ $ins_pos0, $ins_pos1, $args{index}, ] );
422  
423 ### Recurseion for rest
424 0 $self->_make_map( %args, str => $rest, pos => $ins_pos1 );
425 }
426  
427 ### Follow up process
428 elsif (@$map_ref) {
429  
430 @$map_ref =
431 sort {
432 0 ▶ $$a[0] <=> $$b[0]
Condition0%0/6
$Asterisk::config::syntax::highlight::a->[0] <=> $Asterisk::config::syntax::highlight::b->[0] || $Asterisk::config::syntax::highlight::b->[1] <=> $Asterisk::config::syntax::highlight::a->[1] || $Asterisk::config::syntax::highlight::a->[2] <=> $Asterisk::config::syntax::highlight::b->[2]
l!l&&r!l&&!r
000
$Asterisk::config::syntax::highlight::a->[0] <=> $Asterisk::config::syntax::highlight::b->[0] or $Asterisk::config::syntax::highlight::b->[1] <=> $Asterisk::config::syntax::highlight::a->[1]
l!l&&r!l&&!r
000
MC/DC0%0/3
$Asterisk::config::syntax::highlight::a->[0] <=> $Asterisk::config::syntax::highlight::b->[0] || $Asterisk::config::syntax::highlight::b->[1] <=> $Asterisk::config::syntax::highlight::a->[1] || $Asterisk::config::syntax::highlight::a->[2] <=> $Asterisk::config::syntax::highlight::b->[2]
$Asterisk::config::syntax::highlight::a->[0] <=> $Asterisk::config::syntax::highlight::b->[0] $Asterisk::config::syntax::highlight::b->[1] <=> $Asterisk::config::syntax::highlight::a->[1] $Asterisk::config::syntax::highlight::a->[2] <=> $Asterisk::config::syntax::highlight::b->[2]
Truth table0%0/4
A or B || C
A= $Asterisk::config::syntax::highlight::a->[0] <=> $Asterisk::config::syntax::highlight::b->[0]B= $Asterisk::config::syntax::highlight::b->[1] <=> $Asterisk::config::syntax::highlight::a->[1]C= $Asterisk::config::syntax::highlight::a->[2] <=> $Asterisk::config::syntax::highlight::b->[2]
ABCresult
1XX1
01X1
0011
0000
433 or $$b[1] <=> $$a[1]
434 or $$a[2] <=> $$b[2]
435 } @$map_ref;
436 }
437  
438 0 return;
439 }
440  
441 }
442  
443 1 1;
444  
445 __END__
↑ Summary