web/cgi-bin/yatt.lib/YATT/Util/DictOrder.pm

filter: Statementstmt 96.0% 24 / 25 Branchbran 75.0% 6 / 8 Conditioncond 50.0% 3 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 5 / 5 Podpod 100% 2 / 2 totaltotal 82.0% 41 / 50 CC 7 SCAR 16.8
CC
7
Cov
85%
dict_order
7.9
BEGIN
1.0
BEGIN
1.0
CRAP 5.4
« web/cgi-bin/yatt.lib/YATT/LRXML/NodeCursor.pm ↑ Summary web/cgi-bin/yatt.lib/YATT/Class/Configurable.pm »
1 package YATT::Util::DictOrder;
2 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 10 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use base qw/Exporter/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 10 our @EXPORT_OK = qw(&dict_order &dict_sort);
7 10 our @EXPORT = @EXPORT_OK;
8  
9 33 ▶sub dict_order {
Subroutine dict_order: called CC=7 SCAR=20.6
Pod documented
10 33 my ($a, $b, $start) = @_;
11 33 ▶ $start = 1 unless defined $start;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $start 33 0 33
12 33 my ($result, $i) = (0);
13 33 ▶ for ($i = $start; $i <= $#$a and $i <= $#$b; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $a->$#* and $i <= $b->$#*) 66 0 66
Condition33%1/3
$i <= $a->$#* and $i <= $b->$#*
!ll&&!rl&&r
0066
MC/DC0%0/2
$i <= $a->$#* and $i <= $b->$#*
$i <= $a->$#* $i <= $b->$#*
Truth table33%1/3
A and B
A= $i <= $a->$#*B= $i <= $b->$#*
ABresult
0X0
100
111
14 66 ▶ if ($a->[$i] =~ /^\d/ and $b->[$i] =~ /^\d/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a->[$i] =~ /^\d/ and $b->[$i] =~ /^\d/) { } 33 33 66
Condition66%2/3
$a->[$i] =~ /^\d/ and $b->[$i] =~ /^\d/
!ll&&!rl&&r
33033
MC/DC50%1/2
$a->[$i] =~ /^\d/ and $b->[$i] =~ /^\d/
$a->[$i] =~ /^\d/ $b->[$i] =~ /^\d/
Truth table66%2/3
A and B
A= $a->[$i] =~ /^\d/B= $b->[$i] =~ /^\d/
ABresult
0X0
100
111
15 33 $result = $a->[$i] <=> $b->[$i];
16 } else {
17 33 $result = $a->[$i] cmp $b->[$i];
18 }
19 66 ▶ return $result unless $result == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $result == 0 33 33 66
20 }
21 0 return $#$a <=> $#$b;
22 }
23  
24 # a => ['a', 'a']
25 # q1a => ['q1a', 'q', 1, 'a']
26 # q11b => ['q11b', 'q', 11, 'b']
27 1 ▶sub dict_sort (@) {
Subroutine dict_sort: called CC=1 SCAR=0.0
Pod documented
28 1 map {$_->[0]} sort {dict_order($a,$b)} map {[$_, split /(\d+)/]} @_;
29 }
30  
31 10 1;
32  
33 =head1 NAME
34  
35 YATT::Util::DictOrder - Dictionary-style ordering and sorting.
36  
37 =head1 SYNOPSIS
38  
39 use YATT::Util::DictOrder;
40 print join ",", dict_sort qw(q3-1 q3 q10a q1);
41 # prints "q1,q3,q3-1,q10a"
42  
43 print join ",",
44 map {$$_[0]}
45 sort {dict_order($a, $b, 1)}
46 map {[$$_[0], split /(\d+)/, $$_[1]]}
47 [qw(foo q3-1)],
48 [qw(summer q3)],
49 [qw(moe q10a)],
50 [qw(romantic q1)];
51 # prints "romantic,summer,foo,moe"
52  
53 =head1 DESCRIPTION
54  
55 =head2 C<dict_sort>
56  
57 =head2 C<dict_order>
58  
59 =head1 AUTHOR
60  
61 KOBAYASI, Hiroaki (C<hkoba@cpan.org>)
62  
63 =head1 LICENSE
64  
65 This library is free software; you may redistribute it and/or modify
66 it under the same terms as Perl itself.
67  
68 =cut
« web/cgi-bin/yatt.lib/YATT/LRXML/NodeCursor.pm ↑ Summary web/cgi-bin/yatt.lib/YATT/Class/Configurable.pm »