line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::DBI::Column; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Class::DBI::Column - A column in a table |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $column = Class::DBI::Column->new($name); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $name = $column->name; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my @groups = $column->groups; |
14
|
|
|
|
|
|
|
my $pri_col = $colg->primary; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
if ($column->in_database) { ... } |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 DESCRIPTION |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Each Class::DBI class maintains a list of its columns as class data. |
21
|
|
|
|
|
|
|
This provides an interface to those columns. You probably shouldn't be |
22
|
|
|
|
|
|
|
dealing with this directly. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 METHODS |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
4
|
|
|
4
|
|
25
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
152
|
|
29
|
4
|
|
|
4
|
|
22
|
use base 'Class::Accessor::Fast'; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
4096
|
|
30
|
4
|
|
|
4
|
|
2587
|
use Carp; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
406
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors( |
33
|
|
|
|
|
|
|
qw/name accessor mutator placeholder is_constrained/ |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
use overload |
37
|
186
|
|
|
186
|
|
8780
|
'""' => sub { shift->name_lc }, |
38
|
4
|
|
|
4
|
|
7985
|
fallback => 1; |
|
4
|
|
|
|
|
5098
|
|
|
4
|
|
|
|
|
39
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 new |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $column = Class::DBI::Column->new($column) |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
A new object for this column. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub new { |
49
|
32
|
|
|
32
|
1
|
46
|
my $class = shift; |
50
|
32
|
50
|
|
|
|
404
|
my $name = shift or croak "Column needs a name"; |
51
|
32
|
|
100
|
|
|
267
|
my $opt = shift || {}; |
52
|
32
|
|
|
|
|
272
|
return $class->SUPER::new( |
53
|
|
|
|
|
|
|
{ |
54
|
|
|
|
|
|
|
name => $name, |
55
|
|
|
|
|
|
|
accessor => $name, |
56
|
|
|
|
|
|
|
mutator => $name, |
57
|
|
|
|
|
|
|
_groups => {}, |
58
|
|
|
|
|
|
|
placeholder => '?', |
59
|
|
|
|
|
|
|
%$opt, |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
261
|
|
|
261
|
0
|
663
|
sub name_lc { lc shift->name } |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub add_group { |
67
|
36
|
|
|
36
|
0
|
218
|
my ($self, $group) = @_; |
68
|
36
|
|
|
|
|
4031
|
$self->{_groups}->{$group} = 1; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub groups { |
72
|
34
|
|
|
34
|
0
|
41
|
my $self = shift; |
73
|
34
|
|
|
|
|
33
|
my %groups = %{ $self->{_groups} }; |
|
34
|
|
|
|
|
124
|
|
74
|
34
|
100
|
|
|
|
92
|
delete $groups{All} if keys %groups > 1; |
75
|
34
|
|
|
|
|
191
|
return keys %groups; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub in_database { |
79
|
32
|
|
|
32
|
0
|
66
|
return !scalar grep $_ eq "TEMP", shift->groups; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |