blib/script/stag-autoschema.pl untested

filter: Statementstmt 0.0% 0 / 58 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod n/a totaltotal 0.0% 0 / 76 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/local/bin/perl -w
2  
3 # POD docs at bottom of file
4  
5  
6 use strict;
7  
8 use Carp;
9 use Data::Stag qw(:all);
10 use Getopt::Long;
11  
12 my $parser = "";
13 my $handler = "sxpr";
14 my $mapf;
15 my $tosql;
16 my $toxml;
17 my $toperl;
18 my $debug;
19 my $help;
20 my $name;
21 my $defs;
22 my $dtd;
23 GetOptions(
24 "help|h"=>\$help,
25 "parser|format|p=s" => \$parser,
26 "handler|writer|w=s" => \$handler,
27 "xml"=>\$toxml,
28 "perl"=>\$toperl,
29 "debug"=>\$debug,
30 "name|n=s"=>\$name,
31 "defs"=>\$defs,
32 "dtd"=>\$dtd,
33 );
34 if ($help) {
35 system("perldoc $0");
36 exit 0;
37 }
38  
39 $dtd = 1 if $handler eq 'dtd';
40  
41 #my @hdr = ();
42 #if ($name) {
43 # push(@hdr, (name=>$name));
44 #}
45  
46 my @files = @ARGV;
47 my $tree = Data::Stag->new(null=>[]);
48 foreach my $fn (@files) {
49  
50 my $curr_tree =
51 Data::Stag->parse($fn,
52 $parser);
53 $tree->name($curr_tree->name);
54 $tree->addkid($_) foreach $curr_tree->subnodes;
55 }
56  
57 my $s = $tree->autoschema;
58 if ($defs) {
59 my @sdefs = ();
60 my %u = ();
61 $s->iterate(sub {
62 my $stag = shift;
63 my $n = $stag->name;
64 $n =~ s/[\+\?\*]$//;
65 return if $u{$n};
66 $u{$n}=1;
67 push(@sdefs, ($n=>''));
68 return;
69 });
70 $s = Data::Stag->unflatten(schemadefs=>[@sdefs]);
71 } else {
72 $s->iterate(sub {
73 my $stag = shift;
74 my $d = $stag->data;
75 if (!ref $d) {
76 $stag->data($d =~ /INT/ ? "i" : "s");
77 }
78 });
79 }
80 # my $top =
81 # Data::Stag->unflatten(schema=>[
82 # @hdr,
83 # ]);
84 # $top->set_nesting($s->data);
85 if ($dtd) {
86 print $s->dtd;
87 } else {
88 print $s->generate(-fmt=>$handler);
89 }
90  
91 __END__