tools/gen_commands.pl

filter: Statementstmt 95.4% 42 / 44 Branchbran 92.8% 13 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 95.0% 58 / 61 CC 9 SCAR 20.2
CC
9
Cov
95%
print_command
9.0
BEGIN
1.0
BEGIN
1.0
CRAP 7.5
« tools/gen_help.pl ↑ Summary blib/lib/XML/XSH2/Inline.pm »
1 #!/usr/bin/perl
2  
3 # $Id: gen_commands.pl,v 2.3 2007-11-13 21:54:18 pajas Exp $
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶if ($ARGV[0]=~'^(-h|--help)?$') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ARGV[0] =~ /^(-h|--help)?$/) 0 1 1
9 0 print <<EOF;
10 Generates XSH commands specifications RecDescentXML source.
11  
12 Usage: $0 <source.xml>
13  
14 EOF
15 0 exit;
16 }
17  
18 1 my $parser=XML::LibXML->new();
19 1 $parser->load_ext_dtd(1);
20 1 $parser->validation(1);
21 1 $parser->complete_attributes(1);
22 1 my $doc=$parser->parse_file($ARGV[0]);
23  
24 1 my $dom=$doc->getDocumentElement();
25 1 my ($rules)=$dom->findnodes('./rules');
26  
27 1 print "# This file was automatically generated from $ARGV[0] on \n# ",scalar(localtime),"\n";
28  
29 1 print "package XML::XSH2::Functions;\n\n";
30 1 print "%COMMANDS = (\n";
31 1 foreach my $r ($rules->findnodes('./rule[command]')) {
32 102 print_command($r);
33 }
34 1 print ");\n\n1;\n";
35  
36 1 exit;
37  
38 ## ================================================
39  
40 sub print_command {
41 102 ▶ my ($rule) = @_;
Subroutine print_command: called CC=9 SCAR=22.0
42 102 my $name = $rule->getAttribute('name');
43 102 foreach ($rule->findnodes(q{aliases/alias/@name})) {
44 64 print "'",$_->value(),"' => '$name',\n";
45 }
46 102 my ($cmd) = $rule->findnodes(q{command});
47 102 print "'$name' => [";
48 # print "\\\&",$cmd->getAttribute('func');
49 102 print "'",$cmd->getAttribute('func'),"'";
50 102 ▶ print ", ",($cmd->getAttribute('minargs') ne "" ? $cmd->getAttribute('minargs') : 0);
Branch: 1 branch
BranchTrueFalseTotal
$cmd->getAttribute('minargs') ne '' ? : 66 36 102
51 102 ▶ print ", ",($cmd->getAttribute('maxargs') ne "" ? $cmd->getAttribute('maxargs') : "undef");
Branch: 1 branch
BranchTrueFalseTotal
$cmd->getAttribute('maxargs') ne '' ? : 98 4 102
52 102 my @params = $cmd->findnodes(q{param});
53 102 ▶ if (@params) {
Branch: 1 branch
BranchTrueFalseTotal
if (@params) { } 32 70 102
54 32 print ",\n\t{\n\t";
55 32 foreach my $param (@params) {
56 115 ▶ if ($param->getAttribute('short') ne "") {
Branch: 1 branch
BranchTrueFalseTotal
if ($param->getAttribute("short") ne "") 114 1 115
57 114 print " '".$param->getAttribute('short')."' => '",
58 $param->getAttribute('name')
59 ,"',\n\t";
60 114 ▶ print " '".$param->getAttribute('name')."' => ",
Branch: 1 branch
BranchTrueFalseTotal
$param->getAttribute('argument') ne '' ? : 32 82 114
61 ($param->getAttribute('argument') ne "" ? "'".$param->getAttribute('type')."'"
62 : "''"),",\n\t";
63 }
64 }
65 32 print "}"
66 } else {
67 70 print ",undef";
68 }
69 102 ▶ if ($cmd->getAttribute('extraargs') ne "") {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd->getAttribute("extraargs") ne "") 15 87 102
70 15 print ", ".$cmd->getAttribute('extraargs');
71 }
72 102 print "],\n";
73 }
74  
« tools/gen_help.pl ↑ Summary blib/lib/XML/XSH2/Inline.pm »