← 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:57:06 2010

File /project/perl/lib/Class/DBI/Relationship.pm
Statements Executed 129
Statement Execution Time 3.88ms
Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
511888µs124msClass::DBI::Relationship::::_add_triggersClass::DBI::Relationship::_add_triggers
511593µs164msClass::DBI::Relationship::::set_upClass::DBI::Relationship::set_up
511584µs38.8msClass::DBI::Relationship::::_initClass::DBI::Relationship::_init
522477µs2.72msClass::DBI::Relationship::::_set_up_class_dataClass::DBI::Relationship::_set_up_class_data
511332µs1.06msClass::DBI::Relationship::::_add_methodsClass::DBI::Relationship::_add_methods
31131µs31µsClass::DBI::Relationship::::methodsClass::DBI::Relationship::methods
0000s0sClass::DBI::Relationship::::BEGINClass::DBI::Relationship::BEGIN
0000s0sClass::DBI::Relationship::::remap_argumentsClass::DBI::Relationship::remap_arguments
0000s0sClass::DBI::Relationship::::triggersClass::DBI::Relationship::triggers
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::Relationship;
2
3382µs127µsuse strict;
# spent 27µs making 1 call to strict::import
4390µs1120µsuse warnings;
# spent 120µs making 1 call to warnings::import
5
63708µs10suse base 'Class::Accessor::Fast';
# spent 293µs making 1 call to base::import, recursion: max depth 4, time 293µs
7
8134µs11.06ms__PACKAGE__->mk_accessors(qw/name class accessor foreign_class args/);
# spent 1.06ms making 1 call to Class::Accessor::mk_accessors
9
10
# spent 164ms (593µs+163) within Class::DBI::Relationship::set_up which was called 5 times, avg 32.8ms/call: # 5 times (593µs+163ms) by Class::DBI::__ANON__[/project/perl/lib/Class/DBI.pm:1034] at line 1033 of Class/DBI.pm, avg 32.8ms/call
sub set_up {
11526µs my $proto = shift;
125125µs538.8ms my $self = $proto->_init(@_);
# spent 39.8ms making 5 calls to Class::DBI::Relationship::_init, avg 7.96ms/call, recursion: max depth 1, time 956µs
13598µs54.94ms $self->_set_up_class_data;
# spent 3.10ms making 3 calls to Class::DBI::Relationship::HasA::_set_up_class_data, avg 1.03ms/call # spent 1.84ms making 2 calls to Class::DBI::Relationship::HasMany::_set_up_class_data, avg 922µs/call
145118µs5124ms $self->_add_triggers;
# spent 124ms making 5 calls to Class::DBI::Relationship::_add_triggers, avg 24.7ms/call
155123µs51.06ms $self->_add_methods;
# spent 1.06ms making 5 calls to Class::DBI::Relationship::_add_methods, avg 212µs/call
16589µs $self;
17}
18
19
# spent 38.8ms (584µs+38.3) within Class::DBI::Relationship::_init which was called 5 times, avg 7.77ms/call: # 5 times (584µs+38.3ms) by Class::DBI::Relationship::set_up at line 12, avg 7.77ms/call
sub _init {
20525µs my $proto = shift;
21525µs my $name = shift;
22598µs538.8ms my ($class, $accessor, $foreign_class, $args) = $proto->remap_arguments(@_);
# spent 37.9ms making 2 calls to Class::DBI::Relationship::HasMany::remap_arguments, avg 19.0ms/call # spent 904µs making 3 calls to Class::DBI::Relationship::HasA::remap_arguments, avg 301µs/call
235142µs566µs $class->clear_object_index;
# spent 66µs making 5 calls to Class::DBI::clear_object_index, avg 13µs/call
245254µs5320µs return $proto->new(
# spent 320µs making 5 calls to Class::Accessor::new, avg 64µs/call
25 {
26 name => $name,
27 class => $class,
28 foreign_class => $foreign_class,
29 accessor => $accessor,
30 args => $args,
31 }
32 );
33}
34
35sub remap_arguments {
36 my $self = shift;
37 return @_;
38}
39
40
# spent 2.72ms (477µs+2.24) within Class::DBI::Relationship::_set_up_class_data which was called 5 times, avg 544µs/call: # 3 times (295µs+1.34ms) by Class::DBI::Relationship::HasA::_set_up_class_data at line 95 of Class/DBI/Relationship/HasA.pm, avg 544µs/call # 2 times (182µs+906µs) by Class::DBI::Relationship::HasMany::_set_up_class_data at line 59 of Class/DBI/Relationship/HasMany.pm, avg 544µs/call
sub _set_up_class_data {
41527µs my $self = shift;
425444µs202.24ms $self->class->_extend_meta($self->name => $self->accessor => $self);
# spent 2.03ms making 5 calls to Class::DBI::_extend_meta, avg 407µs/call # spent 208µs making 15 calls to Class::Accessor::Fast::__ANON__[Class/Accessor/Fast.pm:41], avg 14µs/call
43}
44
45sub triggers { () }
46
47
# spent 124ms (888µs+123) within Class::DBI::Relationship::_add_triggers which was called 5 times, avg 24.7ms/call: # 5 times (888µs+123ms) by Class::DBI::Relationship::set_up at line 14, avg 24.7ms/call
sub _add_triggers {
48527µs my $self = shift;
49
50 # need to treat as list in case there are multiples for the same point.
515104µs5120ms my @triggers = $self->triggers or return;
# spent 112ms making 3 calls to Class::DBI::Relationship::HasA::triggers, avg 37.4ms/call # spent 7.93ms making 2 calls to Class::DBI::Relationship::HasMany::triggers, avg 3.97ms/call
525109µs while (my ($point, $subref) = (splice @triggers, 0, 2)) {
5314574µs282.47ms $self->class->add_trigger($point => $subref);
# spent 2.28ms making 14 calls to Class::DBI::add_trigger, avg 163µs/call # spent 194µs making 14 calls to Class::Accessor::Fast::__ANON__[Class/Accessor/Fast.pm:41], avg 14µs/call
54 }
55}
56
57345µs
# spent 31µs within Class::DBI::Relationship::methods which was called 3 times, avg 10µs/call: # 3 times (31µs+0s) by Class::DBI::Relationship::_add_methods at line 61, avg 10µs/call
sub methods { () }
58
59
# spent 1.06ms (332µs+729µs) within Class::DBI::Relationship::_add_methods which was called 5 times, avg 212µs/call: # 5 times (332µs+729µs) by Class::DBI::Relationship::set_up at line 15, avg 212µs/call
sub _add_methods {
60524µs my $self = shift;
615129µs5700µs my %methods = $self->methods or return;
# spent 669µs making 2 calls to Class::DBI::Relationship::HasMany::methods, avg 334µs/call # spent 31µs making 3 calls to Class::DBI::Relationship::methods, avg 10µs/call
62236µs229µs my $class = $self->class;
# spent 29µs making 2 calls to Class::Accessor::Fast::__ANON__[Class/Accessor/Fast.pm:41], avg 14µs/call
633187µs1105µs no strict 'refs';
# spent 105µs making 1 call to strict::unimport
64255µs foreach my $method (keys %methods) {
65472µs *{"$class\::$method"} = $methods{$method};
66 }
67}
68
69114µs1;
70
71__END__
72
73=head1 NAME
74
75Class::DBI::Relationship - base class for Relationships
76
77=head1 DESCRIPTION
78
79A Class::DBI class represents a database table. But merely being able
80to represent single tables isn't really that useful - databases are all
81about relationships.
82
83So, Class::DBI provides a variety of Relationship models to represent
84common database occurences (HasA, HasMany and MightHave), and provides
85a way to add others.
86
87=head1 SUBCLASSING
88
89Relationships should inherit from Class::DBI::Relationship, and
90provide a variety of methods to represent the relationship. For
91examples of how these are used see Class::DBI::Relationship::HasA,
92Class::DBI::Relationship::HasMany and Class::DBI::Relationship::MightHave.
93
94=head2 remap_arguments
95
96 sub remap_arguments {
97 my $self = shift;
98 # process @_;
99 return ($class, accessor, $foreign_class, $args)
100 }
101
102Subclasses should define a 'remap_arguments' method that takes the
103arguments with which your relationship method will be called, and
104transforms them into the structure that the Relationship modules requires.
105If this method is not provided, then it is assumed that your method will
106be called with these 3 arguments in this order.
107
108This should return a list of 4 items:
109
110=over 4
111
112=item class
113
114The Class::DBI subclass to which this relationship applies. This will be
115passed in to you from the caller who actually set up the relationship,
116and is available for you to call methods on whilst performing this
117mapping. You should almost never need to change this.
118
119This usually an entire application base class (or Class::DBI itself),
120but could be a single class wishing to override a default relationship.
121
122=item accessor
123
124The method in the class which will provide access to the results of
125the relationship.
126
127=item foreign_class
128
129The class for the table with which the class has a relationship.
130
131=item args
132
133Any additional args that your relationship requires. It is recommended
134that you use this as a hashref to store any extra information your
135relationship needs rather than adding extra accessors, as this information
136will all be stored in the 'meta_info'.
137
138=back
139
140=head2 triggers
141
142 sub triggers {
143 return (
144 before_create => sub { ... },
145 after_create => sub { ... },
146 );
147 }
148
149Subclasses may define a 'triggers' method that returns a list of
150triggers that the relationship needs. This method can be omitted if
151there are no triggers to be set up.
152
153=head2 methods
154
155 sub methods {
156 return (
157 method1 => sub { ... },
158 method2 => sub { ... },
159 );
160 }
161
162Subclasses may define a 'methods' method that returns a list of methods
163to facilitate the relationship that should be created in the calling
164Class::DBI class. This method can be omitted if there are no methods
165to be set up.
166
167=cut