script/war

filter: Statementstmt 62.2% 28 / 45 Branchbran 43.7% 7 / 16 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 85.7% 6 / 7 Podpod n/a totaltotal 56.1% 41 / 73 CC 6 SCAR 17.9
CC
6
Cov
55%
report
12.0
_items
7.7
BEGIN
1.0
CRAP 6.0
↑ Summary blib/lib/App/War.pm »
1 #!/usr/bin/env perl
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use App::War;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 our $VERSION = $App::War::VERSION;
10  
11 =pod
12  
13 =head1 NAME
14  
15 war - break one big decision into lots of little decisions
16  
17 =head1 SYNOPSIS
18  
19 war [--help] [--man] [--version]
20 war [--graph] --file sourcefile
21 war [--graph] alt1 alt2 alt3 ...
22  
23 =head1 DESCRIPTION
24  
25 Imagine you're at a department store, trying to choose one china pattern
26 out of a dozen or more alternatives. How do you do it? If none stands out
27 as the clear winner, you might apply a process of elimination to your
28 choices, until a winner emerges.
29  
30 This application applies a process similar to that described above: first,
31 the set of alternatives is defined. Then pairs of alternatives are
32 presented to the user, who chooses one "winner" from each pair. The
33 process continues until an unambiguous ordering of the alternatives is
34 known.
35  
36 =head1 OPTIONS
37  
38 =over 4
39  
40 =item B<--file> filename, B<-f> filename
41  
42 Reads the list of alternatives from file C<filename>, a text file
43 containing the items to be ranked. Blank lines are ignored, as well as
44 lines starting with the pound (C<#>) character.
45  
46 =item B<--graph>, B<-g>
47  
48 When the results are shown to the user, also display a textual
49 representation of the preference graph.
50  
51 =item B<--help>, B<-h>, B<-?>
52  
53 Display simple command-line options.
54  
55 =item B<--man>
56  
57 Display detailed script information.
58  
59 =item B<--version>, B<-v>
60  
61 Shows the current script version.
62  
63 =back
64  
65 =head1 EXAMPLE
66  
67 To choose our favorite bug, we could do the following:
68  
69 % war aphid bee cricket
70 Choose one of the following:
71 <1> aphid
72 <2> bee
73 2
74 Choose one of the following:
75 <1> cricket
76 <2> bee
77 1
78 ===== final preference order =====
79 cricket
80 bee
81 aphid
82 %
83  
84 =head1 SEE ALSO
85  
86 =over 4
87  
88 =item L<App::War>
89  
90 Information on access to the source code, bug tracking, and smoke testing
91 can be found in the L<App::War> documentation.
92  
93 =item L<http://en.wikipedia.org/wiki/Paired_comparison>
94  
95 =item L<http://en.wikipedia.org/wiki/Law_of_comparative_judgment>
96  
97 =item L<http://en.wikipedia.org/wiki/Analytic_Hierarchy_Process>
98  
99 =item L<http://www.kittenwar.com>
100  
101 =back
102  
103 =head1 AUTHOR
104  
105 John Trammell, C<< <johntrammell@gmail.com> >>
106  
107 =cut
108  
109 1 our %OPT = ();
110 1 my @OPTIONS = qw/ file|f=s graph|g help|h|? man version|v /;
111 1 ▶GetOptions(\%OPT,@OPTIONS) || pod2usage;
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions(\%main::OPT, @OPTIONS) or pod2usage() 1 0 1
112 0 ▶if ($OPT{version}) { die "Using App::War v$VERSION\n" }
Branch: 1 branch
BranchTrueFalseTotal
if ($main::OPT{"version"}) 0 1 1
113 0 ▶if ($OPT{man}) { pod2usage(-verbose => 2); }
Branch: 1 branch
BranchTrueFalseTotal
if ($main::OPT{"man"}) 0 1 1
114 0 ▶if ($OPT{help}) { pod2usage(-exitval => 0); }
Branch: 1 branch
BranchTrueFalseTotal
if ($main::OPT{"help"}) 0 1 1
115  
116 # get items
117 1 my @items = _items();
118 1 ▶unless (@items) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@items) 1 0 1
119 1 pod2usage(-msg => 'No items specified.', -verbose => 0, -exitval => 0);
120 }
121  
122 # fight the war
123 0 my $war = App::War->new(items => \@items)->run;
124  
125 # print the results
126 0 report($war);
127  
128 # read the items from the file specified on the command line
129 1 ▶sub _items {
Subroutine _items: called CC=4 SCAR=20.4
130 1 ▶ return @ARGV if @ARGV;
Branch: 1 branch
BranchTrueFalseTotal
if @ARGV 0 1 1
131 1 ▶ open(my $h,q(<),$OPT{file}) or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open my $h, "<", $main::OPT{"file"} or die $! 1 0 1
132 0 ▶ return grep { /\S/ && !/^#/ } map { chomp; $_ } <$h>;
Condition0%0/3
/\S/ && !/^#/
!ll&&!rl&&r
000
MC/DC0%0/2
/\S/ && !/^#/
/\S/ !/^#/
Truth table0%0/3
A && not(B)
A= /\S/B= !/^#/
ABresult
0X0
100
111
133 }
134  
135 0 ▶sub report {
Subroutine report: not called CC=3 SCAR=24.8
136 0 my $war = shift;
137 0 ▶ if ($OPT{graph}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::OPT{"graph"}) 0 0 0
138 0 print "graph: @{[ $war->graph ]}\n";
139 }
140 0 my @items = $war->items;
141 0 print "===== final preference order =====\n";
142 0 for (map { $items[$_] } $war->graph->topological_sort) {
143 0 print $_, "\n";
144 }
145 }
146  
↑ Summary blib/lib/App/War.pm »