← Index
NYTProf Performance Profile   « block view • line view • sub view »
For ddd2.pl
  Run on Tue May 25 16:52:24 2010
Reported on Tue May 25 16:56:55 2010

File /project/perl/lib/Class/DBI/Plugin/RetrieveAll.pm
Statements Executed 25
Statement Execution Time 1.14ms
Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111169µs868msClass::DBI::Plugin::RetrieveAll::::__ANON__[:77]Class::DBI::Plugin::RetrieveAll::__ANON__[:77]
111163µs826µsClass::DBI::Plugin::RetrieveAll::::importClass::DBI::Plugin::RetrieveAll::import
11191µs868msClass::DBI::Plugin::RetrieveAll::::__ANON__[:93]Class::DBI::Plugin::RetrieveAll::__ANON__[:93]
11156µs216µsClass::DBI::Plugin::RetrieveAll::::__ANON__[:84]Class::DBI::Plugin::RetrieveAll::__ANON__[:84]
0000s0sClass::DBI::Plugin::RetrieveAll::::BEGINClass::DBI::Plugin::RetrieveAll::BEGIN
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Class::DBI::Plugin::RetrieveAll;
2
316µsour $VERSION = '1.04';
4
5391µs127µsuse strict;
# spent 27µs making 1 call to strict::import
63149µs1119µsuse warnings;
# spent 119µs making 1 call to warnings::import
7
8=head1 NAME
9
10Class::DBI::Plugin::RetrieveAll - more complex retrieve_all() for Class::DBI
11
12=head1 SYNOPSIS
13
14 use base 'Class::DBI';
15 use Class::DBI::Plugin::RetrieveAll;
16
17 my @by_date = My::Class->retrieve_all_sorted_by("date");
18
19 # or
20
21 __PACKAGE__->retrieve_all_sort_field('date');
22
23 my @by_date = My::Class->retrieve_all;
24
25=head1 DESCRIPTION
26
27This is a simple plugin to a Class::DBI subclass that allows for simple
28sorting of the results of a retrieve_all().
29
30There are two main ways to use this.
31
32Firstly, we create a new method 'retrieve_all_sorted_by' which takes an
33argument of how to sort.
34
35We also add a method for 'retrieve_all_sort_field' that sets a default
36field that any retrieve_all() will use for sorting.
37
38=head1 METHODS
39
40=head2 retrieve_all_sorted_by
41
42 my @by_date = My::Class->retrieve_all_sorted_by("date");
43
44This method will be exported into the calling class, and allows for
45retrieving all the objects of the class, sorted by the given column.
46
47The argument given will be passed straight through to the database 'as
48is', and is not checked in any way, so an error here will usually
49in an error from the database, rather than Class::DBI itself.
50
51This makes it possible to pass more complex ORDER BY clauses through:
52
53 my @by_date = My::Class->retrieve_all_sorted_by("date DESC, reference_no");
54
55=head2 retrieve_all_sort_field
56
57 __PACKAGE__->retrieve_all_sort_field('date');
58
59This method changes the default retrieve_all() in the Class to be
60auto-sorted by the field given. Again this will be passed through
61directly, so you can have complex ORDER BY clauses.
62
63=cut
64
65
# spent 826µs (163+663) within Class::DBI::Plugin::RetrieveAll::import which was called # once (163µs+663µs) by base::import at line 8 of K2/DB2.pm
sub import {
667182µs my $caller = caller();
673485µs194µs no strict 'refs';
# spent 94µs making 1 call to strict::unimport
68
69 $caller->set_sql(retrieve_all_sorted => <<'');
# spent 593µs making 1 call to Class::DBI::set_sql
70 SELECT __ESSENTIAL__
71 FROM __TABLE__
72 ORDER BY %s
73
74
# spent 868ms (169µs+868) within Class::DBI::Plugin::RetrieveAll::__ANON__[/project/perl/lib/Class/DBI/Plugin/RetrieveAll.pm:77] which was called # once (169µs+868ms) by Class::DBI::Plugin::RetrieveAll::__ANON__[/project/perl/lib/Class/DBI/Plugin/RetrieveAll.pm:93] at line 92
*{"$caller\::retrieve_all_sorted_by"} = sub {
752102µs my ($class, $order_by) = @_;
76 return $class->sth_to_objects($class->sql_retrieve_all_sorted($order_by));
# spent 863ms making 1 call to Class::DBI::sth_to_objects # spent 4.69ms making 1 call to Ima::DBI::__ANON__[Ima/DBI.pm:384]
77 };
78
79 $caller->mk_classdata('__plugin_retall_sortfield');
# spent 56µs making 1 call to Class::Data::Inheritable::mk_classdata
80
81
# spent 216µs (56+160) within Class::DBI::Plugin::RetrieveAll::__ANON__[/project/perl/lib/Class/DBI/Plugin/RetrieveAll.pm:84] which was called # once (56µs+160µs) by main::BEGIN at line 10 of Wiki/DB/Wiki.pm
*{"$caller\::retrieve_all_sort_field"} = sub {
82242µs my ($class, $field) = @_;
83 $class->__plugin_retall_sortfield($field);
84 };
85
86 # I hate that SUPER means *my* SUPER *now* - not $class->SUPER then
87 my $super = $caller->can('retrieve_all');
# spent 14µs making 1 call to UNIVERSAL::can
88
# spent 868ms (91µs+868) within Class::DBI::Plugin::RetrieveAll::__ANON__[/project/perl/lib/Class/DBI/Plugin/RetrieveAll.pm:93] which was called # once (91µs+868ms) by main::RUNTIME at line 7 of ddd2.pl
*{"$caller\::retrieve_all"} = sub {
89368µs my $class = shift;
90 my $field = $class->__plugin_retall_sortfield
91 or return $super->($class);
92 return $class->retrieve_all_sorted_by($field);
93 };
94}
95
96=head1 AUTHOR
97
98Tony Bowden
99
100=head1 BUGS and QUERIES
101
102Please direct all correspondence regarding this module to:
103 bug-Class-DBI-Plugin-RetrieveAll@rt.cpan.org
104
105=head1 COPYRIGHT and LICENSE
106
107Copyright (C) 2004-2006 Kasei. All rights reserved.
108
109This module is free software; you can redistribute it and/or modify
110it under the same terms as Perl itself.
111
112=cut
113
114114µs1;
115