File | /project/perl/lib/Class/DBI/ColumnGrouper.pm |
Statements Executed | 4343 |
Statement Execution Time | 52.9ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
466 | 2 | 1 | 26.6ms | 47.9ms | find_column | Class::DBI::ColumnGrouper::
467 | 2 | 2 | 17.4ms | 29.0ms | primary | Class::DBI::ColumnGrouper::
473 | 3 | 1 | 11.7ms | 12.1ms | group_cols | Class::DBI::ColumnGrouper::
4 | 1 | 1 | 677µs | 2.45ms | add_group | Class::DBI::ColumnGrouper::
10 | 1 | 1 | 568µs | 1.14ms | add_column | Class::DBI::ColumnGrouper::
5 | 2 | 1 | 212µs | 364µs | _uniq | Class::DBI::ColumnGrouper::
4 | 2 | 2 | 186µs | 968µs | columns_in | Class::DBI::ColumnGrouper::
3 | 2 | 2 | 169µs | 610µs | essential | Class::DBI::ColumnGrouper::
4 | 1 | 1 | 131µs | 903µs | clone | Class::DBI::ColumnGrouper::
1 | 1 | 1 | 76µs | 330µs | all_columns | Class::DBI::ColumnGrouper::
1 | 1 | 1 | 56µs | 114µs | groups_for | Class::DBI::ColumnGrouper::
1 | 1 | 1 | 36µs | 36µs | new | Class::DBI::ColumnGrouper::
0 | 0 | 0 | 0s | 0s | BEGIN | Class::DBI::ColumnGrouper::
0 | 0 | 0 | 0s | 0s | _unique | Class::DBI::ColumnGrouper::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Class::DBI::ColumnGrouper; | ||||
2 | |||||
3 | =head1 NAME | ||||
4 | |||||
5 | Class::DBI::ColumnGrouper - Columns and Column Groups | ||||
6 | |||||
7 | =head1 SYNOPSIS | ||||
8 | |||||
9 | my $colg = Class::DBI::ColumnGrouper->new; | ||||
10 | $colg->add_group(People => qw/star director producer/); | ||||
11 | |||||
12 | my @cols = $colg->group_cols($group); | ||||
13 | |||||
14 | my @all = $colg->all_columns; | ||||
15 | my @pri_col = $colg->primary; | ||||
16 | my @essential_cols = $colg->essential; | ||||
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 that. You probably don't want to be dealing | ||||
22 | with this directly. | ||||
23 | |||||
24 | =head1 METHODS | ||||
25 | |||||
26 | =cut | ||||
27 | |||||
28 | 3 | 103µs | 1 | 24µs | use strict; # spent 24µs making 1 call to strict::import |
29 | |||||
30 | 3 | 105µs | 1 | 260µs | use Carp; # spent 260µs making 1 call to Exporter::import |
31 | 3 | 399µs | 1 | 472µs | use Storable 'dclone'; # spent 472µs making 1 call to Exporter::import |
32 | 3 | 1.78ms | use Class::DBI::Column; | ||
33 | |||||
34 | sub _unique { | ||||
35 | my %seen; | ||||
36 | map { $seen{$_}++ ? () : $_ } @_; | ||||
37 | } | ||||
38 | |||||
39 | sub _uniq { | ||||
40 | 10 | 97µs | my %tmp; | ||
41 | 1 | 45µs | return grep !$tmp{$_}++, @_; | ||
42 | } | ||||
43 | |||||
44 | =head2 new | ||||
45 | |||||
46 | my $colg = Class::DBI::ColumnGrouper->new; | ||||
47 | |||||
48 | A new blank ColumnnGrouper object. | ||||
49 | |||||
50 | =head2 clone | ||||
51 | |||||
52 | my $colg2 = $colg->clone; | ||||
53 | |||||
54 | Clone an existing ColumnGrouper. | ||||
55 | |||||
56 | =cut | ||||
57 | |||||
58 | # spent 36µs within Class::DBI::ColumnGrouper::new which was called
# once (36µs+0s) by base::import at line 86 of Class/DBI.pm | ||||
59 | 2 | 43µs | my $class = shift; | ||
60 | bless { | ||||
61 | _groups => {}, | ||||
62 | _cols => {}, | ||||
63 | }, $class; | ||||
64 | } | ||||
65 | |||||
66 | # spent 903µs (131+772) within Class::DBI::ColumnGrouper::clone which was called 4 times, avg 226µs/call:
# 4 times (131µs+772µs) by Class::DBI::_set_columns at line 249 of Class/DBI.pm, avg 226µs/call | ||||
67 | 8 | 911µs | my ($class, $prev) = @_; | ||
68 | return dclone $prev; # spent 772µs making 4 calls to Storable::dclone, avg 193µs/call | ||||
69 | } | ||||
70 | |||||
71 | =head2 add_column / find_column | ||||
72 | |||||
73 | $colg->add_column($name); | ||||
74 | my Class::DBI::Column $col = $colg->find_column($name); | ||||
75 | |||||
76 | Add or return a Column object for the given column name. | ||||
77 | |||||
78 | =cut | ||||
79 | |||||
80 | # spent 1.14ms (568µs+572µs) within Class::DBI::ColumnGrouper::add_column which was called 10 times, avg 114µs/call:
# 10 times (568µs+572µs) by Class::DBI::ColumnGrouper::add_group at line 112, avg 114µs/call | ||||
81 | 30 | 598µs | my ($self, $col) = @_; | ||
82 | |||||
83 | # TODO remove this | ||||
84 | croak "Need a Column, got $col" unless $col->isa("Class::DBI::Column"); # spent 104µs making 10 calls to UNIVERSAL::isa, avg 10µs/call | ||||
85 | 1 | 28µs | 10 | 396µs | $self->{_allcol}->{ $col->name_lc } ||= $col; # spent 396µs making 10 calls to Class::DBI::Column::name_lc, avg 40µs/call |
86 | } | ||||
87 | |||||
88 | # spent 47.9ms (26.6+21.3) within Class::DBI::ColumnGrouper::find_column which was called 466 times, avg 103µs/call:
# 463 times (26.4ms+21.2ms) by Class::DBI::_find_columns at line 295 of Class/DBI.pm, avg 103µs/call
# 3 times (165µs+126µs) by Class::DBI::find_column at line 289 of Class/DBI.pm, avg 97µs/call | ||||
89 | 1398 | 11.2ms | my ($self, $name) = @_; | ||
90 | return $name if ref $name; | ||||
91 | 1 | 7.00ms | return unless $self->{_allcol}->{ lc $name }; | ||
92 | } | ||||
93 | |||||
94 | =head2 add_group | ||||
95 | |||||
96 | $colg->add_group(People => qw/star director producer/); | ||||
97 | |||||
98 | This adds a list of columns as a column group. | ||||
99 | |||||
100 | =cut | ||||
101 | |||||
102 | # spent 2.45ms (677µs+1.78) within Class::DBI::ColumnGrouper::add_group which was called 4 times, avg 613µs/call:
# 4 times (677µs+1.78ms) by Class::DBI::_set_columns at line 249 of Class/DBI.pm, avg 613µs/call | ||||
103 | 36 | 633µs | my ($self, $group, @names) = @_; | ||
104 | $self->add_group(Primary => $names[0]) # spent 47µs making 2 calls to Class::DBI::ColumnGrouper::group_cols, avg 24µs/call | ||||
105 | if ($group eq "All" or $group eq "Essential") | ||||
106 | and not $self->group_cols('Primary'); | ||||
107 | $self->add_group(Essential => @names) # spent 399µs making 2 calls to Class::DBI::ColumnGrouper::essential, avg 200µs/call | ||||
108 | if $group eq "All" | ||||
109 | and !$self->essential; | ||||
110 | @names = _unique($self->primary, @names) if $group eq "Essential"; | ||||
111 | |||||
112 | my @cols = map $self->add_column($_), @names; # spent 1.14ms making 10 calls to Class::DBI::ColumnGrouper::add_column, avg 114µs/call | ||||
113 | $_->add_group($group) foreach @cols; # spent 190µs making 10 calls to Class::DBI::Column::add_group, avg 19µs/call | ||||
114 | $self->{_groups}->{$group} = \@cols; | ||||
115 | return $self; | ||||
116 | } | ||||
117 | |||||
118 | =head2 group_cols / groups_for | ||||
119 | |||||
120 | my @colg = $cols->group_cols($group); | ||||
121 | my @groups = $cols->groups_for(@cols); | ||||
122 | |||||
123 | This returns a list of all columns which are in the given group, or the | ||||
124 | groups a given column is in. | ||||
125 | |||||
126 | =cut | ||||
127 | |||||
128 | # spent 12.1ms (11.7+330µs) within Class::DBI::ColumnGrouper::group_cols which was called 473 times, avg 26µs/call:
# 467 times (11.6ms+0s) by Class::DBI::ColumnGrouper::primary at line 178, avg 25µs/call
# 4 times (111µs+330µs) by Class::DBI::ColumnGrouper::columns_in at line 149, avg 110µs/call
# 2 times (47µs+0s) by Class::DBI::ColumnGrouper::add_group at line 104, avg 24µs/call | ||||
129 | 1418 | 13.2ms | my ($self, $group) = @_; | ||
130 | return $self->all_columns if $group eq "All"; # spent 330µs making 1 call to Class::DBI::ColumnGrouper::all_columns | ||||
131 | @{ $self->{_groups}->{$group} || [] }; | ||||
132 | } | ||||
133 | |||||
134 | # spent 114µs (56+58) within Class::DBI::ColumnGrouper::groups_for which was called
# once (56µs+58µs) by Class::DBI::get at line 844 of Class/DBI.pm | ||||
135 | 2 | 49µs | my ($self, @cols) = @_; | ||
136 | return _uniq(map $_->groups, @cols); # spent 35µs making 1 call to Class::DBI::Column::groups
# spent 23µs making 1 call to Class::DBI::ColumnGrouper::_uniq | ||||
137 | } | ||||
138 | |||||
139 | =head2 columns_in | ||||
140 | |||||
141 | my @cols = $colg->columns_in(@groups); | ||||
142 | |||||
143 | This returns a list of all columns which are in the given groups. | ||||
144 | |||||
145 | =cut | ||||
146 | |||||
147 | # spent 968µs (186+782) within Class::DBI::ColumnGrouper::columns_in which was called 4 times, avg 242µs/call:
# 3 times (142µs+127µs) by Class::DBI::ColumnGrouper::essential at line 191, avg 90µs/call
# once (44µs+655µs) by Class::DBI::_flesh at line 854 of Class/DBI.pm | ||||
148 | 8 | 177µs | my ($self, @groups) = @_; | ||
149 | return _uniq(map $self->group_cols($_), @groups); # spent 441µs making 4 calls to Class::DBI::ColumnGrouper::group_cols, avg 110µs/call
# spent 341µs making 4 calls to Class::DBI::ColumnGrouper::_uniq, avg 85µs/call | ||||
150 | } | ||||
151 | |||||
152 | =head2 all_columns | ||||
153 | |||||
154 | my @all = $colg->all_columns; | ||||
155 | |||||
156 | This returns a list of all the real columns. | ||||
157 | |||||
158 | =head2 primary | ||||
159 | |||||
160 | my $pri_col = $colg->primary; | ||||
161 | |||||
162 | This returns a list of the columns in the Primary group. | ||||
163 | |||||
164 | =head2 essential | ||||
165 | |||||
166 | my @essential_cols = $colg->essential; | ||||
167 | |||||
168 | This returns a list of the columns in the Essential group. | ||||
169 | |||||
170 | =cut | ||||
171 | |||||
172 | # spent 330µs (76+254) within Class::DBI::ColumnGrouper::all_columns which was called
# once (76µs+254µs) by Class::DBI::ColumnGrouper::group_cols at line 130 | ||||
173 | 2 | 78µs | my $self = shift; | ||
174 | return grep $_->in_database, values %{ $self->{_allcol} }; # spent 254µs making 4 calls to Class::DBI::Column::in_database, avg 64µs/call | ||||
175 | } | ||||
176 | |||||
177 | # spent 29.0ms (17.4+11.6) within Class::DBI::ColumnGrouper::primary which was called 467 times, avg 62µs/call:
# 464 times (17.3ms+11.5ms) by Class::DBI::primary_column at line 275 of Class/DBI.pm, avg 62µs/call
# 3 times (107µs+65µs) by Class::DBI::ColumnGrouper::essential at line 192, avg 57µs/call | ||||
178 | 1401 | 16.4ms | 467 | 11.6ms | my @cols = shift->group_cols('Primary'); # spent 11.6ms making 467 calls to Class::DBI::ColumnGrouper::group_cols, avg 25µs/call |
179 | if (!wantarray && @cols > 1) { | ||||
180 | local ($Carp::CarpLevel) = 1; | ||||
181 | confess( | ||||
182 | "Multiple columns in Primary group (@cols) but primary called in scalar context" | ||||
183 | ); | ||||
184 | return $cols[0]; | ||||
185 | } | ||||
186 | return @cols; | ||||
187 | } | ||||
188 | |||||
189 | # spent 610µs (169+441) within Class::DBI::ColumnGrouper::essential which was called 3 times, avg 203µs/call:
# 2 times (114µs+285µs) by Class::DBI::ColumnGrouper::add_group at line 107, avg 200µs/call
# once (55µs+156µs) by Class::DBI::_essential at line 285 of Class/DBI.pm | ||||
190 | 12 | 163µs | my $self = shift; | ||
191 | my @cols = $self->columns_in('Essential'); # spent 269µs making 3 calls to Class::DBI::ColumnGrouper::columns_in, avg 90µs/call | ||||
192 | @cols = $self->primary unless @cols; # spent 172µs making 3 calls to Class::DBI::ColumnGrouper::primary, avg 57µs/call | ||||
193 | return @cols; | ||||
194 | } | ||||
195 | |||||
196 | 1 | 14µs | 1; |