| File | /project/perl/lib/Class/DBI/Relationship.pm |
| Statements Executed | 129 |
| Statement Execution Time | 3.88ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 5 | 1 | 1 | 888µs | 124ms | Class::DBI::Relationship::_add_triggers |
| 5 | 1 | 1 | 593µs | 164ms | Class::DBI::Relationship::set_up |
| 5 | 1 | 1 | 584µs | 38.8ms | Class::DBI::Relationship::_init |
| 5 | 2 | 2 | 477µs | 2.72ms | Class::DBI::Relationship::_set_up_class_data |
| 5 | 1 | 1 | 332µs | 1.06ms | Class::DBI::Relationship::_add_methods |
| 3 | 1 | 1 | 31µs | 31µs | Class::DBI::Relationship::methods |
| 0 | 0 | 0 | 0s | 0s | Class::DBI::Relationship::BEGIN |
| 0 | 0 | 0 | 0s | 0s | Class::DBI::Relationship::remap_arguments |
| 0 | 0 | 0 | 0s | 0s | Class::DBI::Relationship::triggers |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Class::DBI::Relationship; | ||||
| 2 | |||||
| 3 | 3 | 82µs | 1 | 27µs | use strict; # spent 27µs making 1 call to strict::import |
| 4 | 3 | 90µs | 1 | 120µs | use warnings; # spent 120µs making 1 call to warnings::import |
| 5 | |||||
| 6 | 3 | 708µs | 1 | 0s | use base 'Class::Accessor::Fast'; # spent 293µs making 1 call to base::import, recursion: max depth 4, time 293µs |
| 7 | |||||
| 8 | 1 | 34µs | 1 | 1.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 | ||||
| 11 | 30 | 579µs | my $proto = shift; | ||
| 12 | 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 | ||||
| 13 | $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 | ||||
| 14 | $self->_add_triggers; # spent 124ms making 5 calls to Class::DBI::Relationship::_add_triggers, avg 24.7ms/call | ||||
| 15 | $self->_add_methods; # spent 1.06ms making 5 calls to Class::DBI::Relationship::_add_methods, avg 212µs/call | ||||
| 16 | $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 | ||||
| 20 | 25 | 544µs | my $proto = shift; | ||
| 21 | my $name = shift; | ||||
| 22 | 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 | ||||
| 23 | $class->clear_object_index; # spent 66µs making 5 calls to Class::DBI::clear_object_index, avg 13µs/call | ||||
| 24 | 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 | |||||
| 35 | sub 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 | ||||
| 41 | 10 | 471µs | my $self = shift; | ||
| 42 | $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 | |||||
| 45 | sub 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 | ||||
| 48 | 29 | 814µs | my $self = shift; | ||
| 49 | |||||
| 50 | # need to treat as list in case there are multiples for the same point. | ||||
| 51 | 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 | ||||
| 52 | while (my ($point, $subref) = (splice @triggers, 0, 2)) { | ||||
| 53 | $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 | |||||
| 57 | 3 | 45µ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 | ||
| 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 | ||||
| 60 | 18 | 316µs | my $self = shift; | ||
| 61 | 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 | ||||
| 62 | my $class = $self->class; # spent 29µs making 2 calls to Class::Accessor::Fast::__ANON__[Class/Accessor/Fast.pm:41], avg 14µs/call | ||||
| 63 | 3 | 187µs | 1 | 105µs | no strict 'refs'; # spent 105µs making 1 call to strict::unimport |
| 64 | foreach my $method (keys %methods) { | ||||
| 65 | *{"$class\::$method"} = $methods{$method}; | ||||
| 66 | } | ||||
| 67 | } | ||||
| 68 | |||||
| 69 | 1 | 14µs | 1; | ||
| 70 | |||||
| 71 | __END__ | ||||
| 72 | |||||
| 73 | =head1 NAME | ||||
| 74 | |||||
| 75 | Class::DBI::Relationship - base class for Relationships | ||||
| 76 | |||||
| 77 | =head1 DESCRIPTION | ||||
| 78 | |||||
| 79 | A Class::DBI class represents a database table. But merely being able | ||||
| 80 | to represent single tables isn't really that useful - databases are all | ||||
| 81 | about relationships. | ||||
| 82 | |||||
| 83 | So, Class::DBI provides a variety of Relationship models to represent | ||||
| 84 | common database occurences (HasA, HasMany and MightHave), and provides | ||||
| 85 | a way to add others. | ||||
| 86 | |||||
| 87 | =head1 SUBCLASSING | ||||
| 88 | |||||
| 89 | Relationships should inherit from Class::DBI::Relationship, and | ||||
| 90 | provide a variety of methods to represent the relationship. For | ||||
| 91 | examples of how these are used see Class::DBI::Relationship::HasA, | ||||
| 92 | Class::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 | |||||
| 102 | Subclasses should define a 'remap_arguments' method that takes the | ||||
| 103 | arguments with which your relationship method will be called, and | ||||
| 104 | transforms them into the structure that the Relationship modules requires. | ||||
| 105 | If this method is not provided, then it is assumed that your method will | ||||
| 106 | be called with these 3 arguments in this order. | ||||
| 107 | |||||
| 108 | This should return a list of 4 items: | ||||
| 109 | |||||
| 110 | =over 4 | ||||
| 111 | |||||
| 112 | =item class | ||||
| 113 | |||||
| 114 | The Class::DBI subclass to which this relationship applies. This will be | ||||
| 115 | passed in to you from the caller who actually set up the relationship, | ||||
| 116 | and is available for you to call methods on whilst performing this | ||||
| 117 | mapping. You should almost never need to change this. | ||||
| 118 | |||||
| 119 | This usually an entire application base class (or Class::DBI itself), | ||||
| 120 | but could be a single class wishing to override a default relationship. | ||||
| 121 | |||||
| 122 | =item accessor | ||||
| 123 | |||||
| 124 | The method in the class which will provide access to the results of | ||||
| 125 | the relationship. | ||||
| 126 | |||||
| 127 | =item foreign_class | ||||
| 128 | |||||
| 129 | The class for the table with which the class has a relationship. | ||||
| 130 | |||||
| 131 | =item args | ||||
| 132 | |||||
| 133 | Any additional args that your relationship requires. It is recommended | ||||
| 134 | that you use this as a hashref to store any extra information your | ||||
| 135 | relationship needs rather than adding extra accessors, as this information | ||||
| 136 | will 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 | |||||
| 149 | Subclasses may define a 'triggers' method that returns a list of | ||||
| 150 | triggers that the relationship needs. This method can be omitted if | ||||
| 151 | there 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 | |||||
| 162 | Subclasses may define a 'methods' method that returns a list of methods | ||||
| 163 | to facilitate the relationship that should be created in the calling | ||||
| 164 | Class::DBI class. This method can be omitted if there are no methods | ||||
| 165 | to be set up. | ||||
| 166 | |||||
| 167 | =cut |