line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::MoCo::Schema; |
2
|
15
|
|
|
15
|
|
84
|
use strict; |
|
15
|
|
|
|
|
28
|
|
|
15
|
|
|
|
|
492
|
|
3
|
15
|
|
|
15
|
|
84
|
use Carp; |
|
15
|
|
|
|
|
28
|
|
|
15
|
|
|
|
|
6577
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
sub new { |
6
|
20
|
|
|
20
|
0
|
49
|
my $class = shift; |
7
|
20
|
50
|
|
|
|
99
|
my $klass = shift or return; |
8
|
20
|
|
|
|
|
160
|
my $self = { |
9
|
|
|
|
|
|
|
class => $klass, |
10
|
|
|
|
|
|
|
primary_keys => undef, |
11
|
|
|
|
|
|
|
uniquie_keys => undef, |
12
|
|
|
|
|
|
|
retrieve_keys => undef, |
13
|
|
|
|
|
|
|
utf8_columns => undef, |
14
|
|
|
|
|
|
|
columns => undef, |
15
|
|
|
|
|
|
|
}; |
16
|
20
|
|
|
|
|
126
|
bless $self, $class; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub primary_keys { |
20
|
273
|
|
|
273
|
0
|
461
|
my $self = shift; |
21
|
273
|
100
|
|
|
|
885
|
unless ($self->{primary_keys}) { |
22
|
10
|
|
|
|
|
29
|
my $class = $self->{class}; |
23
|
10
|
|
|
|
|
81
|
$self->{primary_keys} = $class->db->primary_keys($class->table); |
24
|
|
|
|
|
|
|
} |
25
|
273
|
|
|
|
|
33060
|
$self->{primary_keys}; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub unique_keys { |
29
|
15
|
|
|
15
|
0
|
41
|
my $self = shift; |
30
|
15
|
100
|
|
|
|
59
|
unless ($self->{unique_keys}) { |
31
|
3
|
|
|
|
|
9
|
my $class = $self->{class}; |
32
|
3
|
|
|
|
|
15
|
$self->{unique_keys} = $class->db->unique_keys($class->table); |
33
|
|
|
|
|
|
|
} |
34
|
15
|
|
|
|
|
3889
|
$self->{unique_keys}; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub retrieve_keys { |
38
|
153
|
|
|
153
|
0
|
272
|
my $self = shift; |
39
|
153
|
50
|
|
|
|
447
|
$self->{retrieve_keys} = $_[0] if $_[0]; |
40
|
153
|
|
|
|
|
1914
|
return $self->{retrieve_keys}; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub utf8_columns { |
44
|
5
|
|
|
5
|
0
|
9
|
my $self = shift; |
45
|
5
|
100
|
|
|
|
18
|
if (@_) { |
46
|
1
|
50
|
33
|
|
|
13
|
my $cols = (ref $_[0] and ref $_[0] eq 'ARRAY') ? $_[0] : [ @_ ]; |
47
|
1
|
|
|
|
|
7
|
$self->{utf8_columns} = $cols; |
48
|
|
|
|
|
|
|
|
49
|
1
|
|
|
|
|
3
|
my $class = $self->{class}; |
50
|
15
|
|
|
15
|
|
88
|
no strict 'refs'; |
|
15
|
|
|
|
|
31
|
|
|
15
|
|
|
|
|
3944
|
|
51
|
1
|
|
|
|
|
3
|
for my $col (@$cols) { |
52
|
2
|
|
|
|
|
7
|
my $method = $class . '::' . $col; |
53
|
2
|
|
|
|
|
16
|
*$method = $class->_column_as_handler($col, 'utf8'); |
54
|
|
|
|
|
|
|
# warn $method; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
5
|
|
|
|
|
42
|
return $self->{utf8_columns}; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub columns { |
61
|
183
|
|
|
183
|
0
|
301
|
my $self = shift; |
62
|
183
|
100
|
|
|
|
636
|
unless ($self->{columns}) { |
63
|
18
|
|
|
|
|
53
|
my $class = $self->{class}; |
64
|
18
|
|
|
|
|
92
|
$self->{columns} = $class->db->columns($class->table); |
65
|
|
|
|
|
|
|
} |
66
|
183
|
|
|
|
|
2450
|
$self->{columns}; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub param { |
70
|
4
|
|
|
4
|
0
|
18
|
my $self = shift; |
71
|
4
|
100
|
|
|
|
25
|
return $self->{$_[0]} if not exists $_[1]; |
72
|
2
|
50
|
|
|
|
9
|
@_ % 2 and croak |
73
|
|
|
|
|
|
|
sprintf "%s : You gave me an odd number of parameters to param()"; |
74
|
2
|
|
|
|
|
9
|
my %args = @_; |
75
|
2
|
|
|
|
|
20
|
$self->{$_} = $args{$_} for keys %args; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 NAME |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
DBIx::MoCo::Schema - Schema class for DBIx::MoCo classes |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 SYNOPSIS |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $schema = DBIx::MoCo::Schema->new('MyMoCoClass'); # make an instance |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
my $schema = MyMoCoClass->schema; # MyMoCoClass isa DBIx::MoCo |
89
|
|
|
|
|
|
|
$schema->primary_keys; # same as MyMoCoClass->primary_keys |
90
|
|
|
|
|
|
|
$schema->uniquie_keys; # same as MyMoCoClass->uniquie_keys |
91
|
|
|
|
|
|
|
$schema->columns; # same as MyMoCoClass->columns |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# you can set any parameters using param |
94
|
|
|
|
|
|
|
$schema->param(validation => { |
95
|
|
|
|
|
|
|
name => ['NOT_BLANK', 'ASCII', ['LENGTH', 2, 5]], |
96
|
|
|
|
|
|
|
# for example, FormValidator::Simple style definitions |
97
|
|
|
|
|
|
|
}); |
98
|
|
|
|
|
|
|
$schema->param('validation'); # returns validation definitions |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 SEE ALSO |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
L, L |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 AUTHOR |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Junya Kondo, Ejkondo@hatena.comE |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Copyright (C) Hatena Inc. All Rights Reserved. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
This library is free software; you may redistribute it and/or modify |
113
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |