Sybase/Introspect/Views.pm

filter: Statementstmt 100% 38 / 38 Branchbran 62.5% 5 / 8 Conditioncond 59.2% 16 / 27 MC/DCmcdc 16.6% 2 / 12 Subroutinesub 100% 4 / 4 Podpod 100% 2 / 2 totaltotal 73.6% 67 / 91 CC 20 SCAR 31.0
CC
20
Cov
81%
fetch
25.3
BEGIN
1.0
BEGIN
1.0
CRAP 22.2
« Sybase/DDL.pm ↑ Summary Sybase/Storage/ASE/LOBWriter.pm »
1 package DBIO::Sybase::Introspect::Views;
2 # ABSTRACT: Introspect Sybase ASE view definitions
3  
4 29 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 29 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 29 our $VERSION = '0.900007';
8  
9  
10 15 ▶sub fetch {
Subroutine fetch: called CC=20 SCAR=32.3
Pod documented
11 15 my ($class, $dbh, $schema, $tables) = @_;
12 15 ▶ $schema //= 'dbo';
Condition50%1/2
$schema //= "dbo"
l!l
150
MC/DC0%0/1
$schema //= "dbo"
$schema
Truth table50%1/2
A
A= $schema
Aresult
11
00
13 15 ▶ $tables //= {};
Condition50%1/2
$tables //= {}
l!l
150
MC/DC0%0/1
$tables //= {}
$tables
Truth table50%1/2
A
A= $tables
Aresult
11
00
14 17 my %is_view = map { $_ => 1 }
15 15 ▶ grep { ($tables->{$_}{kind} // '') eq 'view' } keys %$tables;
Condition50%1/2
$tables->{$_}{"kind"} // ""
l!l
450
MC/DC0%0/1
$tables->{$_}{"kind"} // ""
$tables->{$_}{"kind"}
Truth table50%1/2
A
A= $tables->{$_}{"kind"}
Aresult
11
00
16  
17 15 my $rows = $dbh->selectall_arrayref(q{
18 SELECT o.name AS view_name, m.colid2, m.colid, m.text
19 FROM syscomments m
20 JOIN sysobjects o ON o.id = m.id
21 JOIN sysusers u ON u.uid = o.uid
22 WHERE o.type = 'V' AND u.name = ?
23 ORDER BY o.name, m.colid2, m.colid
24 }, { Slice => {} }, $schema);
25  
26 15 my %text;
27 15 for my $row (sort {
28 $a->{view_name} cmp $b->{view_name}
29 || ($a->{colid2} // 0) <=> ($b->{colid2} // 0)
30 20 ▶ || ($a->{colid} // 0) <=> ($b->{colid} // 0)
Condition57%8/14
$DBIO::Sybase::Introspect::Views::a->{'view_name'} cmp $DBIO::Sybase::Introspect::Views::b->{'view_name'} || ($DBIO::Sybase::Introspect::Views::a->{'colid2'} // 0) <=> ($DBIO::Sybase::Introspect::Views::b->{'colid2'} // 0) || ($DBIO::Sybase::Introspect::Views::a->{'colid'} // 0) <=> ($DBIO::Sybase::Introspect::Views::b->{'colid'} // 0)
l!l&&r!l&&!r
4160
$DBIO::Sybase::Introspect::Views::a->{"view_name"} cmp $DBIO::Sybase::Introspect::Views::b->{"view_name"} or ($DBIO::Sybase::Introspect::Views::a->{"colid2"} // 0) <=> ($DBIO::Sybase::Introspect::Views::b->{"colid2"} // 0)
l!l&&r!l&&!r
4016
$DBIO::Sybase::Introspect::Views::a->{"colid2"} // 0
l!l
160
$DBIO::Sybase::Introspect::Views::b->{"colid2"} // 0
l!l
160
$DBIO::Sybase::Introspect::Views::a->{"colid"} // 0
l!l
160
$DBIO::Sybase::Introspect::Views::b->{"colid"} // 0
l!l
160
MC/DC0%0/3
$DBIO::Sybase::Introspect::Views::a->{'view_name'} cmp $DBIO::Sybase::Introspect::Views::b->{'view_name'} || ($DBIO::Sybase::Introspect::Views::a->{'colid2'} // 0) <=> ($DBIO::Sybase::Introspect::Views::b->{'colid2'} // 0) || ($DBIO::Sybase::Introspect::Views::a->{'colid'} // 0) <=> ($DBIO::Sybase::Introspect::Views::b->{'colid'} // 0)
$DBIO::Sybase::Introspect::Views::a->{"view_name"} cmp $DBIO::Sybase::Introspect::Views::b->{"view_name"} $DBIO::Sybase::Introspect::Views::a->{"colid2"} $DBIO::Sybase::Introspect::Views::a->{"colid"}
MC/DC0%0/1
$DBIO::Sybase::Introspect::Views::b->{"colid2"} // 0
$DBIO::Sybase::Introspect::Views::b->{"colid2"}
MC/DC0%0/1
$DBIO::Sybase::Introspect::Views::b->{"colid"} // 0
$DBIO::Sybase::Introspect::Views::b->{"colid"}
Truth table25%1/4
A or B || C
A= $DBIO::Sybase::Introspect::Views::a->{"view_name"} cmp $DBIO::Sybase::Introspect::Views::b->{"view_name"}B= $DBIO::Sybase::Introspect::Views::a->{"colid2"}C= $DBIO::Sybase::Introspect::Views::a->{"colid"}
ABCresult
1XX1
01X1
0011
0000
Truth table50%1/2
A
A= $DBIO::Sybase::Introspect::Views::b->{"colid2"}
Aresult
11
00
Truth table50%1/2
A
A= $DBIO::Sybase::Introspect::Views::b->{"colid"}
Aresult
11
00
31 } @$rows) {
32 33 ▶ next unless $is_view{ $row->{view_name} };
Branch: 1 branch
BranchTrueFalseTotal
unless $is_view{$row->{"view_name"}} 0 33 33
33 33 ▶ $text{ $row->{view_name} } .= $row->{text} // '';
Condition50%1/2
$row->{"text"} // ""
l!l
330
MC/DC0%0/1
$row->{"text"} // ""
$row->{"text"}
Truth table50%1/2
A
A= $row->{"text"}
Aresult
11
00
34 }
35  
36 15 my $deps = $dbh->selectall_arrayref(q{
37 SELECT DISTINCT o.name AS view_name, r.name AS depends_on
38 FROM sysdepends d
39 JOIN sysobjects o ON o.id = d.id
40 JOIN sysusers u ON u.uid = o.uid
41 JOIN sysobjects r ON r.id = d.depid
42 WHERE o.type = 'V' AND r.type = 'V' AND u.name = ?
43 }, { Slice => {} }, $schema);
44  
45 15 my %depends;
46 15 for my $dep (@$deps) {
47 17 ▶ next unless $is_view{ $dep->{view_name} } && $is_view{ $dep->{depends_on} };
Branch: 1 branch
BranchTrueFalseTotal
unless $is_view{$dep->{"view_name"}} and $is_view{$dep->{"depends_on"}} 15 2 17
Condition66%2/3
$is_view{$dep->{"view_name"}} and $is_view{$dep->{"depends_on"}}
!ll&&!rl&&r
0152
MC/DC50%1/2
$is_view{$dep->{"view_name"}} and $is_view{$dep->{"depends_on"}}
$is_view{$dep->{"view_name"}} $is_view{$dep->{"depends_on"}}
Truth table66%2/3
A and B
A= $is_view{$dep->{"view_name"}}B= $is_view{$dep->{"depends_on"}}
ABresult
0X0
100
111
48 2 ▶ next if $dep->{view_name} eq $dep->{depends_on};
Branch: 1 branch
BranchTrueFalseTotal
if $dep->{"view_name"} eq $dep->{"depends_on"} 0 2 2
49 2 $depends{ $dep->{view_name} }{ $dep->{depends_on} } = 1;
50 }
51  
52 15 my %views;
53 15 for my $name (keys %is_view) {
54 17 ▶ next unless exists $text{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $text{$name} 0 17 17
55 $views{$name} = {
56 view_name => $name,
57 definition => strip_head($text{$name}),
58 17 ▶ depends_on => [ sort keys %{ $depends{$name} // {} } ],
Condition100%2/2
$depends{$name} // {}
l!l
116
MC/DC100%1/1
$depends{$name} // {}
$depends{$name}
Truth table100%2/2
A
A= $depends{$name}
Aresult
11
00
59 };
60 }
61  
62 15 return \%views;
63 }
64  
65  
66 20 ▶sub strip_head {
Subroutine strip_head: called CC=1 SCAR=0.0
Pod documented
67 20 my ($def) = @_;
68 20 $def =~ s/\A\s*create\s+view\s+.*?\s+as\s+//is;
69 20 $def =~ s/^\s+//;
70 20 $def =~ s/\s+\z//;
71 20 $def =~ s/\s*;\s*\z//;
72 20 return $def;
73 }
74  
75 29 1;
76  
77 __END__
« Sybase/DDL.pm ↑ Summary Sybase/Storage/ASE/LOBWriter.pm »