| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Maypole::Plugin::ColumnGroups; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
32367
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
33
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
36
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
13762
|
use Maypole::Config; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use NEXT; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.3'; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Maypole::Config->mk_accessors( qw( column_groups field_groups ) ); |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Maypole::Plugin::ColumnGroups - set up column groups in Maypole |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use Maypole::Application qw( ColumnGroups -Debug2 ); |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Maypole will use the column 'name' or 'title', if it exists, or a primary |
|
22
|
|
|
|
|
|
|
# key column that is not called 'id'. Otherwise, you need to tell Maypole |
|
23
|
|
|
|
|
|
|
# what column to stringify objects to: |
|
24
|
|
|
|
|
|
|
__PACKAGE__->config->column_groups( { person => { Stringify => 'first_name' }, |
|
25
|
|
|
|
|
|
|
car => { Stringify => 'model' }, |
|
26
|
|
|
|
|
|
|
widget => { Stringify => 'part_no' }, |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
article => { Editor => [ qw( content keywords publish location ) ], |
|
29
|
|
|
|
|
|
|
Writer => [ qw( content keywords ) ], |
|
30
|
|
|
|
|
|
|
Reviewer => [ qw( rating ) ], |
|
31
|
|
|
|
|
|
|
}, |
|
32
|
|
|
|
|
|
|
finance => { Editor => [ qw( invoice credit bribe entertainment ) ] }, |
|
33
|
|
|
|
|
|
|
} ); |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# |
|
36
|
|
|
|
|
|
|
# An example using Maypole::Plugin::Config::Apache: |
|
37
|
|
|
|
|
|
|
# |
|
38
|
|
|
|
|
|
|
PerlAddVar MaypoleColumnGroups "person => { Stringify => 'first_name' }" |
|
39
|
|
|
|
|
|
|
PerlAddVar MaypoleColumnGroups "car => { Stringify => 'model' }" |
|
40
|
|
|
|
|
|
|
PerlAddVar MaypoleColumnGroups "widget => { Stringify => 'part_no' }" |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
PerlAddVar MaypoleColumnGroups "article => { Editor => [ qw( content keywords publish location ) ] }" |
|
43
|
|
|
|
|
|
|
PerlAddVar MaypoleColumnGroups "article => { Writer => [ qw( content keywords ) ] }" |
|
44
|
|
|
|
|
|
|
PerlAddVar MaypoleColumnGroups "article => { Reviewer => [ qw( rating ) ] }" |
|
45
|
|
|
|
|
|
|
PerlAddVar MaypoleColumnGroups "finance => { Editor => [ qw( invoice credit bribe entertainment ) ] }" |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Maypole use the C column group to decide which column to use when, for example, displaying a |
|
51
|
|
|
|
|
|
|
link to an object. If there is no C group, Maypole defaults to using the column 'name' or 'title', |
|
52
|
|
|
|
|
|
|
if it exists, or a primary key column that is not called 'id'. Otherwise, you need to tell Maypole what |
|
53
|
|
|
|
|
|
|
column to stringify objects on. |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Authorization could make heavy use of column groups to decide who has access |
|
56
|
|
|
|
|
|
|
to what columns of different tables. It's easy enough to set up column groups by hand, but it's also |
|
57
|
|
|
|
|
|
|
useful to be able to stuff all that information into the configuration data. |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
L defines several pairs of C<*_columns> and C<*_fields> accessors in the model |
|
60
|
|
|
|
|
|
|
class, generally one pair for each main template (C, C, C etc.). You could override |
|
61
|
|
|
|
|
|
|
these methods to look up their lists in the C and C config slots. |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Setting the C flag to 2 or higher will print some info to C to confirm how the groups |
|
64
|
|
|
|
|
|
|
have been set up. |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 CONFIGURATION ACCESSORS |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
These methods are added to the Maypole configuration object. |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=over 4 |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=item column_groups |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=item field_groups |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
You may wish to use this slot to store information about different groups of non-column fields. |
|
77
|
|
|
|
|
|
|
For instance, just as C returns a list of columns for general display in templates, |
|
78
|
|
|
|
|
|
|
you may wish to define a C method to list C accessors to use in the same |
|
79
|
|
|
|
|
|
|
circumstances. This config slot provides a convenient location to store that information. |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=back |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 METHODS |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=over 4 |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item setup |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Sets up the CDBI column groups. |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=back |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub setup |
|
96
|
|
|
|
|
|
|
{ |
|
97
|
|
|
|
|
|
|
my $r = shift; |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
$r->NEXT::DISTINCT::setup( @_ ); |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
warn "Running " . __PACKAGE__ . " setup for $r" if $r->debug; |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# $table => { Group => $column or $columns } |
|
104
|
|
|
|
|
|
|
my $col_groups = $r->config->column_groups; |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
my $loader = $r->config->loader; |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
foreach my $table ( keys %$col_groups ) |
|
109
|
|
|
|
|
|
|
{ |
|
110
|
|
|
|
|
|
|
my $groups = $col_groups->{ $table }; |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
foreach my $group ( keys %$groups ) |
|
113
|
|
|
|
|
|
|
{ |
|
114
|
|
|
|
|
|
|
my $cols = $groups->{ $group }; |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
my @cols = ref( $cols ) eq 'ARRAY' ? @$cols : ( $cols ); |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
my $class = $loader->find_class( $table ); |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
$class->columns( $group => @cols ); |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
warn "Added column group '$group' with columns '@cols' to class '$class'\n" if $r->debug > 1; |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 AUTHOR |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
David Baird, C<< >> |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 BUGS |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
|
134
|
|
|
|
|
|
|
C, or through the web interface at |
|
135
|
|
|
|
|
|
|
L. |
|
136
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
|
137
|
|
|
|
|
|
|
your bug as I make changes. |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Copyright 2005 David Baird, All Rights Reserved. |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
146
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=cut |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
1; # End of Maypole::Plugin::ColumnGroups |