Helper/Model/CDBI.pm

filter: Statementstmt 26.5% 13 / 49 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 66.6% 4 / 6 Podpod 100% 2 / 2 totaltotal 26.3% 19 / 72 CC 9 SCAR 34.3
CC
9
Cov
21%
mk_compclass
56.0
mk_comptest
12.0
BEGIN
1.0
CRAP 30.9
↑ Summary Model/CDBI.pm »
1 package Catalyst::Helper::Model::CDBI;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Class::DBI::Loader;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Class::DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 Catalyst::Helper::Model::CDBI - Helper for CDBI Models
11  
12 =head1 SYNOPSIS
13  
14 script/create.pl model CDBI CDBI dsn user password
15  
16 =head1 DESCRIPTION
17  
18 Helper for CDBI Model.
19  
20 =head2 METHODS
21  
22 =over 4
23  
24 =item mk_compclass
25  
26 Reads the database and makes a main model class as well as placeholders
27 for each table.
28  
29 =item mk_comptest
30  
31 Makes tests for the CDBI Model.
32  
33 =back
34  
35 =cut
36  
37 0 ▶sub mk_compclass {
Subroutine mk_compclass: not called CC=7 SCAR=40.3
Pod documented
38 0 my ( $self, $helper, $dsn, $user, $pass ) = @_;
39 0 ▶ $helper->{dsn} = $dsn || '';
Condition0%0/2
$dsn || ''
l!l
00
MC/DC0%0/1
$dsn || ''
$dsn
Truth table0%0/2
A
A= $dsn
Aresult
11
00
40 0 ▶ $helper->{user} = $user || '';
Condition0%0/2
$user || ''
l!l
00
MC/DC0%0/1
$user || ''
$user
Truth table0%0/2
A
A= $user
Aresult
11
00
41 0 ▶ $helper->{pass} = $pass || '';
Condition0%0/2
$pass || ''
l!l
00
MC/DC0%0/1
$pass || ''
$pass
Truth table0%0/2
A
A= $pass
Aresult
11
00
42 0 ▶ $helper->{rel} = $dsn =~ /sqlite|pg|mysql/i ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$dsn =~ /sqlite|pg|mysql/i ? : 0 0 0
43 0 my $file = $helper->{file};
44 0 $helper->{classes} = [];
45 0 $helper->render_file( 'cdbiclass', $file );
46 #push( @{ $helper->{classes} }, $helper->{class} );
47 0 ▶ return 1 unless $dsn;
Branch: 1 branch
BranchTrueFalseTotal
unless $dsn 0 0 0
48 my $loader = Class::DBI::Loader->new(
49 dsn => $dsn,
50 user => $user,
51 password => $pass,
52 namespace => $helper->{class}
53 0 );
54  
55 0 my $path = $file;
56 0 $path =~ s/\.pm$//;
57 0 $helper->mk_dir($path);
58  
59 0 for my $c ( $loader->classes ) {
60 0 $helper->{tableclass} = $c;
61 0 $helper->{tableclass} =~ /\W*(\w+)$/;
62 0 my $f = $1;
63 0 my $p = File::Spec->catfile( $path, "$f.pm" );
64 0 $helper->render_file( 'tableclass', $p );
65 0 push( @{ $helper->{classes} }, $c );
66 }
67 0 return 1;
68 }
69  
70 0 ▶sub mk_comptest {
Subroutine mk_comptest: not called CC=3 SCAR=24.8
Pod documented
71 0 my ( $self, $helper ) = @_;
72 0 my $test = $helper->{test};
73 0 my $name = $helper->{name};
74 0 for my $c ( @{ $helper->{classes} } ) {
75 0 $helper->{tableclass} = $c;
76 0 $helper->{tableclass} =~ /\:\:(\w+)\:\:(\w+)$/;
77 0 my $prefix;
78 0 ▶ unless ( $1 eq 'M' ) { $prefix = "$name\::$2" }
Branch: 1 branch
BranchTrueFalseTotal
if ($1 eq 'M') { } 0 0 0
79 0 else { $prefix = $2 }
80 0 $prefix =~ s/::/-/g;
81 0 my $test = $helper->next_test($prefix);
82 0 $helper->render_file( 'test', $test );
83 }
84 }
85  
86 =head1 SEE ALSO
87  
88 L<Catalyst::Manual>, L<Catalyst::Test>, L<Catalyst::Request>,
89 L<Catalyst::Response>, L<Catalyst::Helper>
90  
91 =head1 AUTHOR
92  
93 Sebastian Riedel, C<sri@oook.de>
94  
95 =head1 LICENSE
96  
97 This library is free software . You can redistribute it and/or modify
98 it under the same terms as perl itself.
99  
100 =cut
101  
102 1 1;
103 __DATA__
↑ Summary Model/CDBI.pm »