Annotate.pm

filter: Statementstmt 38.6% 29 / 75 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 56.2% 9 / 16 Podpod 33.3% 2 / 6 totaltotal 34.7% 40 / 115 CC 10 SCAR 23.0
CC
10
Cov
33%
write_files
30.0
tables
12.0
clean
12.0
CRAP 10.0
↑ Summary Annotate/Driver/SQLite.pm »
1 package DBIx::Schema::Annotate;
2 2 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use DBIx::Inspector;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Smart::Args;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use IO::All;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Module::Load ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 our $VERSION = "0.06";
13  
14 2 our $BLOCK_LINE = '## == Schema Info ==';
15  
16 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
17 0 args(
18 my $class => 'ClassName',
19 my $dbh => 'DBI::db',
20 );
21  
22 0 bless {
23 dbh => $dbh,
24 driver => '',
25 tables => '',
26 }, $class;
27 }
28  
29 0 ▶sub driver {
Subroutine driver: not called CC=2 SCAR=17.9
Pod undocumented
30 0 my $self = shift;
31 0 ▶ $self->{driver} ||= do {
Condition0%0/3
$self->{"driver"} ||= do { my $driver_class = sprintf('%s::Driver::%s', __PACKAGE__, $self->{"dbh"}{"Driver"}{"Name"}); &Module::Load::load($driver_class); $driver_class->new("dbh", $self->{"dbh"}) }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"driver"} ||= do { my $driver_class = sprintf('%s::Driver::%s', __PACKAGE__, $self->{"dbh"}{"Driver"}{"Name"}); &Module::Load::load($driver_class); $driver_class->new("dbh", $self->{"dbh"}) }
$self->{"driver"} do { my $driver_class = sprintf('%s::Driver::%s', __PACKAGE__, $self->{"dbh"}{"Driver"}{"Name"}); &Module::Load::load($driver_class); $driver_class->new("dbh", $self->{"dbh"}) }
Truth table0%0/3
A ||= B
A= $self->{"driver"}B= do { my $driver_class = sprintf('%s::Driver::%s', __PACKAGE__, $self->{"dbh"}{"Driver"}{"Name"}); &Module::Load::load($driver_class); $driver_class->new("dbh", $self->{"dbh"}) }
ABresult
1X1
011
000
32 0 my $driver_class = sprintf('%s::Driver::%s', __PACKAGE__, $self->{dbh}->{Driver}->{Name});
33 0 Module::Load::load($driver_class);
34 0 $driver_class->new(dbh => $self->{dbh});
35 };
36 }
37  
38 0 ▶sub tables {
Subroutine tables: not called CC=3 SCAR=24.8
Pod undocumented
39 0 my $self = shift;
40 0 ▶ $self->{tables} ||= do {
Condition0%0/3
$self->{"tables"} ||= do { my $inspector = "DBIx::Inspector"->new("dbh", $self->{"dbh"}); my @list; foreach my $info ($inspector->tables) { push @list, $info->name; } ; \@list }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"tables"} ||= do { my $inspector = "DBIx::Inspector"->new("dbh", $self->{"dbh"}); my @list; foreach my $info ($inspector->tables) { push @list, $info->name; } ; \@list }
$self->{"tables"} do { my $inspector = "DBIx::Inspector"->new("dbh", $self->{"dbh"}); my @list; foreach my $info ($inspector->tables) { push @list, $info->name; } ; \@list }
Truth table0%0/3
A ||= B
A= $self->{"tables"}B= do { my $inspector = "DBIx::Inspector"->new("dbh", $self->{"dbh"}); my @list; foreach my $info ($inspector->tables) { push @list, $info->name; } ; \@list }
ABresult
1X1
011
000
41 0 my $inspector = DBIx::Inspector->new(dbh => $self->{dbh});
42 0 my @list;
43 0 for my $info ($inspector->tables) {
44 0 push @list, $info->name;
45 }
46 0 \@list;
47 };
48 }
49  
50 0 ▶sub get_table_ddl {
Subroutine get_table_ddl: not called CC=1 SCAR=6.9
Pod undocumented
51 0 args(
52 my $self,
53 my $table_name => 'Str',
54 );
55 0 return $self->driver->table_ddl(table_name => $table_name);
56 }
57  
58 0 ▶sub clean {
Subroutine clean: not called CC=3 SCAR=24.8
Pod undocumented
59 0 args(
60 my $self,
61 my $dir => 'Str',
62 );
63  
64 0 for my $table_name (@{$self->tables}) {
65 0 my $f_path = io->catfile($dir, _camelize($table_name).'.pm');
66 0 ▶ next unless ( -e $f_path);
Branch: 1 branch
BranchTrueFalseTotal
unless -e $f_path 0 0 0
67  
68 0 my $io = io($f_path);
69 0 $io->print(do{
70 0 my $content = $io->all;
71 0 $content =~ s/^$BLOCK_LINE\n.+$BLOCK_LINE\n\n//gms;
72 0 $content;
73 });
74 }
75  
76 }
77  
78 0 ▶sub write_files {
Subroutine write_files: not called CC=5 SCAR=34.0
Pod documented
79 0 args(
80 my $self,
81 my $dir => 'Str',
82 );
83  
84 TABLE:
85 0 for my $table_name (@{$self->tables}) {
86 0 my $io = io->catfile($dir, _camelize($table_name).'.pm');
87 0 ▶ next TABLE unless ( -e $io->pathname);
Branch: 1 branch
BranchTrueFalseTotal
unless -e $io->pathname 0 0 0
88  
89 0 $io->print(do{
90 0 my $content = $io->all;
91 0 my $ddl = $self->get_table_ddl(table_name => $table_name);
92 0 $ddl = encode_utf8($ddl);
93  
94 0 ▶ if ($content =~ m/^$BLOCK_LINE\n(.+)\n$BLOCK_LINE\n\n/ms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ /^$BLOCK_LINE\n(.+)\n$BLOCK_LINE\n\n/ms) 0 0 0
95 0 my $ddl_in_file = $1;
96 0 $ddl_in_file =~ s/^# //gms;
97 0 ▶ next TABLE if $ddl_in_file eq $ddl;
Branch: 1 branch
BranchTrueFalseTotal
if $ddl_in_file eq $ddl 0 0 0
98 }
99  
100 #clean
101 0 $content =~ s/^$BLOCK_LINE\n.+$BLOCK_LINE\n\n//gms;
102 my $annotate = join(
103 "\n" =>
104 $BLOCK_LINE,
105 0 (map { '# '.$_} split('\n', $ddl)),
106 $BLOCK_LINE
107 );
108  
109 0 sprintf("%s\n\n%s",$annotate, $content);
110 });
111 }
112 }
113  
114 0 ▶sub _camelize {
Subroutine _camelize: not called CC=1 SCAR=6.9
115 0 my $s = shift;
116 0 join('', map{ ucfirst $_ } split(/(?<=[A-Za-z])_(?=[A-Za-z])|\b/, $s));
117 }
118  
119  
120 2 1;
121  
122 __END__
↑ Summary Annotate/Driver/SQLite.pm »