lib/VSGDR/tableDependencies.pl untested

filter: Statementstmt 0.0% 0 / 67 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 6 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 98 CC 2 SCAR 9.6
CC
2
Cov
0%
END
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.6
1 #!/usr/bin/perl
2  
3 use Modern::Perl;
4 use 5.010;
5  
6 use autodie qw(:all);
7 no indirect ':fatal';
8  
9 use Carp;
10 use DBI;
11 use Graph;
12  
13 use Getopt::Euclid qw( :vars<opt_> );
14 use Data::Dumper;
15 use VSGDR::StaticData;
16  
17 use version ; our $VERSION = qv('0.01');
18  
19 my %tables;
20 my $tbl = $opt_tablename;
21  
22 my $schema = ($tbl =~ m{ \A ([^.]+) \. ([^.]+) \z }xms) ? $1 : "dbo" ;
23 my $table = ($tbl =~ m{ \A ([^.]+) \. ([^.]+) \z }xms) ? $2 : $tbl;
24 die 'bad tablename' if $table =~ m{ \. }xms or $schema =~ m{ \. }xms; # it went wrong if we still have an embedded .
25  
26 my $combinedName = "${schema}.${table}";
27 my $dbh = DBI->connect("dbi:ODBC:${opt_connection}", q{}, q{}, { AutoCommit => 1, RaiseError => 1 });
28  
29 my $ra_dep = VSGDR::StaticData::dependency($dbh);
30 my $g = Graph->new( 'directed' => 1 ) ;
31  
32 foreach my $rec (@{$ra_dep}) {
33 $g->add_vertex("$$rec[1].$$rec[2]") ;
34 $g->add_vertex("$$rec[4].$$rec[5]") ;
35 $g->add_edge("$$rec[1].$$rec[2]","$$rec[4].$$rec[5]");
36 }
37  
38 # remove any successors....... we're not asked to dump data for these
39 for my $v ( $g->all_successors($combinedName)) {
40 $g->delete_vertex($v);
41 }
42  
43 # remove any unconnected nodes
44 for my $v ( grep {$_ ne $combinedName } $g->vertices() ) {
45 if ( ! $g->is_reachable($combinedName,$v) && ! $g->is_reachable($v,$combinedName) ) {
46 $g->delete_vertex($v);
47 }
48 }
49  
50 if ($g->has_a_cycle() ){
51 warn "There are cycles in the dependencies.";
52 warn "Unsorted List of tables follows.";
53 my @res = $g->vertices();
54 do { $" = "\n"; print "@res"; };
55 }
56 else {
57 my @res = $g->topological_sort();
58 do { $" = "\n"; print "@res"; };
59 }
60  
61 exit ;
62  
63 END {
64 $dbh->disconnect() if $dbh ;
65 }
66  
67  
68  
69 __DATA__