| Filename | /2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/DBIx/Class/PK.pm |
| Statements | Executed 14375 statements in 41.6ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 845 | 1 | 1 | 20.8ms | 128ms | DBIx::Class::PK::_mk_ident_cond |
| 845 | 1 | 1 | 17.4ms | 58.8ms | DBIx::Class::PK::_ident_values |
| 845 | 1 | 1 | 7.45ms | 135ms | DBIx::Class::PK::_storage_ident_condition |
| 1 | 1 | 1 | 10µs | 12µs | DBIx::Class::PK::BEGIN@3 |
| 1 | 1 | 1 | 6µs | 13µs | DBIx::Class::PK::BEGIN@4 |
| 1 | 1 | 1 | 6µs | 57µs | DBIx::Class::PK::BEGIN@6 |
| 0 | 0 | 0 | 0s | 0s | DBIx::Class::PK::ID |
| 0 | 0 | 0 | 0s | 0s | DBIx::Class::PK::_create_ID |
| 0 | 0 | 0 | 0s | 0s | DBIx::Class::PK::id |
| 0 | 0 | 0 | 0s | 0s | DBIx::Class::PK::ident_condition |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package DBIx::Class::PK; | ||||
| 2 | |||||
| 3 | 3 | 16µs | 2 | 14µs | # spent 12µs (10+2) within DBIx::Class::PK::BEGIN@3 which was called:
# once (10µs+2µs) by Class::C3::Componentised::ensure_class_loaded at line 3 # spent 12µs making 1 call to DBIx::Class::PK::BEGIN@3
# spent 2µs making 1 call to strict::import |
| 4 | 3 | 18µs | 2 | 21µs | # spent 13µs (6+7) within DBIx::Class::PK::BEGIN@4 which was called:
# once (6µs+7µs) by Class::C3::Componentised::ensure_class_loaded at line 4 # spent 13µs making 1 call to DBIx::Class::PK::BEGIN@4
# spent 7µs making 1 call to warnings::import |
| 5 | |||||
| 6 | 3 | 365µs | 2 | 109µs | # spent 57µs (6+51) within DBIx::Class::PK::BEGIN@6 which was called:
# once (6µs+51µs) by Class::C3::Componentised::ensure_class_loaded at line 6 # spent 57µs making 1 call to DBIx::Class::PK::BEGIN@6
# spent 51µs making 1 call to base::import |
| 7 | |||||
| 8 | =head1 NAME | ||||
| 9 | |||||
| 10 | DBIx::Class::PK - Primary Key class | ||||
| 11 | |||||
| 12 | =head1 SYNOPSIS | ||||
| 13 | |||||
| 14 | =head1 DESCRIPTION | ||||
| 15 | |||||
| 16 | This class contains methods for handling primary keys and methods | ||||
| 17 | depending on them. | ||||
| 18 | |||||
| 19 | =head1 METHODS | ||||
| 20 | |||||
| 21 | =cut | ||||
| 22 | |||||
| 23 | =head2 id | ||||
| 24 | |||||
| 25 | Returns the primary key(s) for a row. Can't be called as | ||||
| 26 | a class method. | ||||
| 27 | |||||
| 28 | =cut | ||||
| 29 | |||||
| 30 | sub id { | ||||
| 31 | my ($self) = @_; | ||||
| 32 | $self->throw_exception( "Can't call id() as a class method" ) | ||||
| 33 | unless ref $self; | ||||
| 34 | my @id_vals = $self->_ident_values; | ||||
| 35 | return (wantarray ? @id_vals : $id_vals[0]); | ||||
| 36 | } | ||||
| 37 | |||||
| 38 | # spent 58.8ms (17.4+41.4) within DBIx::Class::PK::_ident_values which was called 845 times, avg 70µs/call:
# 845 times (17.4ms+41.4ms) by DBIx::Class::PK::_mk_ident_cond at line 117, avg 70µs/call | ||||
| 39 | 845 | 970µs | my ($self, $use_storage_state) = @_; | ||
| 40 | |||||
| 41 | 845 | 574µs | my (@ids, @missing); | ||
| 42 | |||||
| 43 | 845 | 3.29ms | 845 | 36.4ms | for ($self->_pri_cols) { # spent 36.4ms making 845 calls to DBIx::Class::ResultSourceProxy::_pri_cols, avg 43µs/call |
| 44 | 845 | 4.10ms | 845 | 5.00ms | push @ids, ($use_storage_state and exists $self->{_column_data_in_storage}{$_}) # spent 5.00ms making 845 calls to DBIx::Class::Row::get_column, avg 6µs/call |
| 45 | ? $self->{_column_data_in_storage}{$_} | ||||
| 46 | : $self->get_column($_) | ||||
| 47 | ; | ||||
| 48 | 845 | 2.10ms | push @missing, $_ if (! defined $ids[-1] and ! $self->has_column_loaded ($_) ); | ||
| 49 | } | ||||
| 50 | |||||
| 51 | 845 | 551µs | if (@missing && $self->in_storage) { | ||
| 52 | $self->throw_exception ( | ||||
| 53 | 'Unable to uniquely identify row object with missing PK columns: ' | ||||
| 54 | . join (', ', @missing ) | ||||
| 55 | ); | ||||
| 56 | } | ||||
| 57 | |||||
| 58 | 845 | 3.71ms | return @ids; | ||
| 59 | } | ||||
| 60 | |||||
| 61 | =head2 ID | ||||
| 62 | |||||
| 63 | Returns a unique id string identifying a row object by primary key. | ||||
| 64 | Used by L<DBIx::Class::CDBICompat::LiveObjectIndex> and | ||||
| 65 | L<DBIx::Class::ObjectCache>. | ||||
| 66 | |||||
| 67 | =over | ||||
| 68 | |||||
| 69 | =item WARNING | ||||
| 70 | |||||
| 71 | The default C<_create_ID> method used by this function orders the returned | ||||
| 72 | values by the alphabetical order of the primary column names, B<unlike> | ||||
| 73 | the L</id> method, which follows the same order in which columns were fed | ||||
| 74 | to L<DBIx::Class::ResultSource/set_primary_key>. | ||||
| 75 | |||||
| 76 | =back | ||||
| 77 | |||||
| 78 | =cut | ||||
| 79 | |||||
| 80 | sub ID { | ||||
| 81 | my ($self) = @_; | ||||
| 82 | $self->throw_exception( "Can't call ID() as a class method" ) | ||||
| 83 | unless ref $self; | ||||
| 84 | return undef unless $self->in_storage; | ||||
| 85 | return $self->_create_ID(%{$self->ident_condition}); | ||||
| 86 | } | ||||
| 87 | |||||
| 88 | sub _create_ID { | ||||
| 89 | my ($self, %vals) = @_; | ||||
| 90 | return undef unless 0 == grep { !defined } values %vals; | ||||
| 91 | return join '|', ref $self || $self, $self->result_source->name, | ||||
| 92 | map { $_ . '=' . $vals{$_} } sort keys %vals; | ||||
| 93 | } | ||||
| 94 | |||||
| 95 | =head2 ident_condition | ||||
| 96 | |||||
| 97 | my $cond = $result_source->ident_condition(); | ||||
| 98 | |||||
| 99 | my $cond = $result_source->ident_condition('alias'); | ||||
| 100 | |||||
| 101 | Produces a condition hash to locate a row based on the primary key(s). | ||||
| 102 | |||||
| 103 | =cut | ||||
| 104 | |||||
| 105 | sub ident_condition { | ||||
| 106 | shift->_mk_ident_cond(@_); | ||||
| 107 | } | ||||
| 108 | |||||
| 109 | # spent 135ms (7.45+128) within DBIx::Class::PK::_storage_ident_condition which was called 845 times, avg 160µs/call:
# 845 times (7.45ms+128ms) by DBIx::Class::Row::update at line 503 of DBIx/Class/Row.pm, avg 160µs/call | ||||
| 110 | 845 | 5.76ms | 845 | 128ms | shift->_mk_ident_cond(shift, 1); # spent 128ms making 845 calls to DBIx::Class::PK::_mk_ident_cond, avg 151µs/call |
| 111 | } | ||||
| 112 | |||||
| 113 | # spent 128ms (20.8+107) within DBIx::Class::PK::_mk_ident_cond which was called 845 times, avg 151µs/call:
# 845 times (20.8ms+107ms) by DBIx::Class::PK::_storage_ident_condition at line 110, avg 151µs/call | ||||
| 114 | 845 | 1.15ms | my ($self, $alias, $use_storage_state) = @_; | ||
| 115 | |||||
| 116 | 845 | 4.12ms | 845 | 47.9ms | my @pks = $self->_pri_cols; # spent 47.9ms making 845 calls to DBIx::Class::ResultSourceProxy::_pri_cols, avg 57µs/call |
| 117 | 845 | 3.87ms | 845 | 58.8ms | my @vals = $self->_ident_values($use_storage_state); # spent 58.8ms making 845 calls to DBIx::Class::PK::_ident_values, avg 70µs/call |
| 118 | |||||
| 119 | 845 | 602µs | my (%cond, @undef); | ||
| 120 | 845 | 969µs | my $prefix = defined $alias ? $alias.'.' : ''; | ||
| 121 | 845 | 1.35ms | for my $col (@pks) { | ||
| 122 | 845 | 2.93ms | if (! defined ($cond{$prefix.$col} = shift @vals) ) { | ||
| 123 | push @undef, $col; | ||||
| 124 | } | ||||
| 125 | } | ||||
| 126 | |||||
| 127 | 845 | 513µs | if (@undef && $self->in_storage) { | ||
| 128 | $self->throw_exception ( | ||||
| 129 | 'Unable to construct row object identity condition due to NULL PK columns: ' | ||||
| 130 | . join (', ', @undef) | ||||
| 131 | ); | ||||
| 132 | } | ||||
| 133 | |||||
| 134 | 845 | 4.63ms | return \%cond; | ||
| 135 | } | ||||
| 136 | |||||
| 137 | 1 | 2µs | 1; | ||
| 138 | |||||
| 139 | =head1 AUTHORS | ||||
| 140 | |||||
| 141 | Matt S. Trout <mst@shadowcatsystems.co.uk> | ||||
| 142 | |||||
| 143 | =head1 LICENSE | ||||
| 144 | |||||
| 145 | You may distribute this code under the same terms as Perl itself. | ||||
| 146 | |||||
| 147 | =cut | ||||
| 148 |