line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::DBI::ViewLoader::Auto; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
176514
|
use strict; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
276
|
|
4
|
7
|
|
|
7
|
|
44
|
use warnings; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
442
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Class::DBI::ViewLoader::Auto - Load views for existing Class::DBI classes |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
package MyMovieClass; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use strict; |
17
|
|
|
|
|
|
|
use warnings; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use Class::DBI; |
20
|
|
|
|
|
|
|
use Class::DBI::ViewLoader::Auto; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our @ISA = qw( Class::DBI ); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
__PACKAGE__->connection('dbi:Pg:dbname=mymoviedb', 'me', 'mypasswd'); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# load views from database mymoviedb to MyMovieClass::* |
27
|
|
|
|
|
|
|
@loaded = __PACKAGE__->load_views(); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# load only views starting with film_ |
30
|
|
|
|
|
|
|
@loaded = __PACKAGE__->load_views(qr/^film_/); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# or pass more options: |
33
|
|
|
|
|
|
|
@loaded = __PACKAGE__->load_views( |
34
|
|
|
|
|
|
|
namespace => 'MyMovieClass::View', |
35
|
|
|
|
|
|
|
exclude => qr(^test_), |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head2 DESCRIPTION |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
This module provides a simpler interface to Class::DBI::ViewLoader. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=cut |
43
|
|
|
|
|
|
|
|
44
|
7
|
|
|
7
|
|
40
|
use Carp qw( croak ); |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
433
|
|
45
|
7
|
|
|
7
|
|
38
|
use Exporter; |
|
7
|
|
|
|
|
11
|
|
|
7
|
|
|
|
|
261
|
|
46
|
|
|
|
|
|
|
|
47
|
7
|
|
|
7
|
|
1131
|
use Class::DBI::ViewLoader; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
94
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
our @ISA = qw( Exporter ); |
50
|
|
|
|
|
|
|
our @EXPORT = qw( load_views ); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 EXPORTS |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
This module exports the load_views method into the calling package |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 METHODS |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head2 load_views |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
$loader = $cdbi_class->load_views( %opts or $include ) |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Loads views from the database connection in $cdbi_class. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
The default namespace is the same as the calling class. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
%opts is passed to the Class::DBI::Loader constructor. If a scalar argument is |
69
|
|
|
|
|
|
|
given instead of a hash or hashref, it is interpreted as being the include |
70
|
|
|
|
|
|
|
pattern. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
The options dsn, username, password and options are silently ignored. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
$cdbi_class should always be the leftmost base class of the generated classes. |
75
|
|
|
|
|
|
|
base_classes and left_base_classes options are supported, but it might make more |
76
|
|
|
|
|
|
|
sense to add those bases to the calling class manually. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Returns the same as Class::DBI::ViewLoader->load_views, i.e. a list of loaded |
79
|
|
|
|
|
|
|
classes. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# Class::DBI::ViewLoader options to ignore |
84
|
|
|
|
|
|
|
my @unsupported = qw( dsn username password options ); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub load_views { |
87
|
6
|
|
|
6
|
1
|
1763
|
my $class = shift; |
88
|
6
|
|
|
|
|
12
|
my %opts; |
89
|
|
|
|
|
|
|
|
90
|
6
|
100
|
|
|
|
21
|
if (@_ == 1) { |
91
|
3
|
|
|
|
|
9
|
my $proto = shift; |
92
|
3
|
100
|
|
|
|
13
|
if (ref $proto eq 'HASH') { |
93
|
2
|
|
|
|
|
10
|
%opts = %$proto; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
else { |
96
|
1
|
|
|
|
|
3
|
$opts{'include'} = $proto; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
else { |
100
|
3
|
|
|
|
|
8
|
%opts = @_; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
6
|
|
|
|
|
19
|
delete @opts{@unsupported}; |
104
|
6
|
|
100
|
|
|
38
|
$opts{'namespace'} ||= $class; |
105
|
|
|
|
|
|
|
|
106
|
6
|
|
|
|
|
41
|
Class::DBI::ViewLoader->_compat(\%opts); |
107
|
|
|
|
|
|
|
|
108
|
6
|
100
|
|
|
|
529
|
my $sub = $class->can('db_Main') |
109
|
|
|
|
|
|
|
or croak "$class has no connection"; |
110
|
|
|
|
|
|
|
|
111
|
4
|
|
|
|
|
14
|
my $dbh = &$sub($class); |
112
|
4
|
|
|
|
|
6340
|
my $driver = $dbh->{'Driver'}->{'Name'}; |
113
|
|
|
|
|
|
|
|
114
|
4
|
|
|
|
|
158
|
return Class::DBI::ViewLoader->new(%opts) |
115
|
|
|
|
|
|
|
->_load_driver($driver) |
116
|
|
|
|
|
|
|
->_set_dbi_handle($dbh) |
117
|
|
|
|
|
|
|
->_set_keepalive(1) |
118
|
|
|
|
|
|
|
->add_left_base_classes($class) |
119
|
|
|
|
|
|
|
->load_views; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
__END__ |