| Filename | /usr/share/perl5/DBIx/Class/ResultSourceHandle.pm |
| Statements | Executed 15 statements in 1.16ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 21µs | 34µs | DBIx::Class::ResultSourceHandle::BEGIN@3 |
| 1 | 1 | 1 | 13µs | 49µs | DBIx::Class::ResultSourceHandle::BEGIN@12 |
| 1 | 1 | 1 | 12µs | 66µs | DBIx::Class::ResultSourceHandle::BEGIN@6 |
| 1 | 1 | 1 | 11µs | 48µs | DBIx::Class::ResultSourceHandle::BEGIN@8 |
| 1 | 1 | 1 | 10µs | 20µs | DBIx::Class::ResultSourceHandle::BEGIN@4 |
| 1 | 1 | 1 | 9µs | 160µs | DBIx::Class::ResultSourceHandle::BEGIN@9 |
| 0 | 0 | 0 | 0s | 0s | DBIx::Class::ResultSourceHandle::STORABLE_freeze |
| 0 | 0 | 0 | 0s | 0s | DBIx::Class::ResultSourceHandle::STORABLE_thaw |
| 0 | 0 | 0 | 0s | 0s | DBIx::Class::ResultSourceHandle::__ANON__[:115] |
| 0 | 0 | 0 | 0s | 0s | DBIx::Class::ResultSourceHandle::__ANON__[:12] |
| 0 | 0 | 0 | 0s | 0s | DBIx::Class::ResultSourceHandle::new |
| 0 | 0 | 0 | 0s | 0s | DBIx::Class::ResultSourceHandle::resolve |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package DBIx::Class::ResultSourceHandle; | ||||
| 2 | |||||
| 3 | 2 | 51µs | 2 | 47µs | # spent 34µs (21+13) within DBIx::Class::ResultSourceHandle::BEGIN@3 which was called:
# once (21µs+13µs) by DBIx::Class::ResultSource::BEGIN@9 at line 3 # spent 34µs making 1 call to DBIx::Class::ResultSourceHandle::BEGIN@3
# spent 13µs making 1 call to strict::import |
| 4 | 2 | 43µs | 2 | 30µs | # spent 20µs (10+10) within DBIx::Class::ResultSourceHandle::BEGIN@4 which was called:
# once (10µs+10µs) by DBIx::Class::ResultSource::BEGIN@9 at line 4 # spent 20µs making 1 call to DBIx::Class::ResultSourceHandle::BEGIN@4
# spent 10µs making 1 call to warnings::import |
| 5 | |||||
| 6 | 2 | 88µs | 2 | 66µs | # spent 66µs (12+54) within DBIx::Class::ResultSourceHandle::BEGIN@6 which was called:
# once (12µs+54µs) by DBIx::Class::ResultSource::BEGIN@9 at line 6 # spent 66µs making 1 call to DBIx::Class::ResultSourceHandle::BEGIN@6
# spent 54µs making 1 call to base::import, recursion: max depth 1, sum of overlapping time 54µs |
| 7 | |||||
| 8 | 2 | 68µs | 2 | 86µs | # spent 48µs (11+38) within DBIx::Class::ResultSourceHandle::BEGIN@8 which was called:
# once (11µs+38µs) by DBIx::Class::ResultSource::BEGIN@9 at line 8 # spent 48µs making 1 call to DBIx::Class::ResultSourceHandle::BEGIN@8
# spent 38µs making 1 call to Exporter::import |
| 9 | 2 | 232µs | 2 | 311µs | # spent 160µs (9+151) within DBIx::Class::ResultSourceHandle::BEGIN@9 which was called:
# once (9µs+151µs) by DBIx::Class::ResultSource::BEGIN@9 at line 9 # spent 160µs making 1 call to DBIx::Class::ResultSourceHandle::BEGIN@9
# spent 151µs making 1 call to namespace::clean::import |
| 10 | |||||
| 11 | use overload | ||||
| 12 | # spent 49µs (13+36) within DBIx::Class::ResultSourceHandle::BEGIN@12 which was called:
# once (13µs+36µs) by DBIx::Class::ResultSource::BEGIN@9 at line 13 | ||||
| 13 | 2 | 658µs | 2 | 85µs | fallback => 1; # spent 49µs making 1 call to DBIx::Class::ResultSourceHandle::BEGIN@12
# spent 36µs making 1 call to overload::import |
| 14 | |||||
| 15 | 1 | 17µs | 1 | 217µs | __PACKAGE__->mk_group_accessors('simple' => qw/schema source_moniker _detached_source/); # spent 217µs making 1 call to Class::Accessor::Grouped::mk_group_accessors |
| 16 | |||||
| 17 | # Schema to use when thawing. | ||||
| 18 | 1 | 0s | our $thaw_schema; | ||
| 19 | |||||
| 20 | =head1 NAME | ||||
| 21 | |||||
| 22 | DBIx::Class::ResultSourceHandle - Serializable pointers to ResultSource instances | ||||
| 23 | |||||
| 24 | =head1 DESCRIPTION | ||||
| 25 | |||||
| 26 | Currently instances of this class are used to allow proper serialization of | ||||
| 27 | L<ResultSources|DBIx::Class::ResultSource> (which may contain unserializable | ||||
| 28 | elements like C<CODE> references). | ||||
| 29 | |||||
| 30 | Originally this module was used to remove the fixed link between | ||||
| 31 | L<Rows|DBIx::Class::Row>/L<ResultSets|DBIx::Class::ResultSet> and the actual | ||||
| 32 | L<result source objects|DBIx::Class::ResultSource> in order to obviate the need | ||||
| 33 | of keeping a L<schema instance|DBIx::Class::Schema> constantly in scope, while | ||||
| 34 | at the same time avoiding leaks due to circular dependencies. This is however | ||||
| 35 | no longer needed after introduction of a proper mutual-assured-destruction | ||||
| 36 | contract between a C<Schema> instance and its C<ResultSource> registrants. | ||||
| 37 | |||||
| 38 | =head1 METHODS | ||||
| 39 | |||||
| 40 | =head2 new | ||||
| 41 | |||||
| 42 | =cut | ||||
| 43 | |||||
| 44 | sub new { | ||||
| 45 | my ($class, $args) = @_; | ||||
| 46 | my $self = bless $args, ref $class || $class; | ||||
| 47 | |||||
| 48 | unless( ($self->{schema} || $self->{_detached_source}) && $self->{source_moniker} ) { | ||||
| 49 | my $err = 'Expecting a schema instance and a source moniker'; | ||||
| 50 | $self->{schema} | ||||
| 51 | ? $self->{schema}->throw_exception($err) | ||||
| 52 | : DBIx::Class::Exception->throw($err) | ||||
| 53 | } | ||||
| 54 | |||||
| 55 | $self; | ||||
| 56 | } | ||||
| 57 | |||||
| 58 | =head2 resolve | ||||
| 59 | |||||
| 60 | Resolve the moniker into the actual ResultSource object | ||||
| 61 | |||||
| 62 | =cut | ||||
| 63 | |||||
| 64 | sub resolve { | ||||
| 65 | return $_[0]->{schema}->source($_[0]->source_moniker) if $_[0]->{schema}; | ||||
| 66 | |||||
| 67 | $_[0]->_detached_source || DBIx::Class::Exception->throw( sprintf ( | ||||
| 68 | # vague error message as this is never supposed to happen | ||||
| 69 | "Unable to resolve moniker '%s' - please contact the dev team at %s", | ||||
| 70 | $_[0]->source_moniker, | ||||
| 71 | DBIx::Class::_ENV_::HELP_URL, | ||||
| 72 | ), 'full_stacktrace'); | ||||
| 73 | } | ||||
| 74 | |||||
| 75 | =head2 STORABLE_freeze | ||||
| 76 | |||||
| 77 | Freezes a handle. | ||||
| 78 | |||||
| 79 | =cut | ||||
| 80 | |||||
| 81 | sub STORABLE_freeze { | ||||
| 82 | my ($self, $cloning) = @_; | ||||
| 83 | |||||
| 84 | my $to_serialize = { %$self }; | ||||
| 85 | |||||
| 86 | delete $to_serialize->{schema}; | ||||
| 87 | delete $to_serialize->{_detached_source}; | ||||
| 88 | $to_serialize->{_frozen_from_class} = $self->{schema} | ||||
| 89 | ? $self->{schema}->class($self->source_moniker) | ||||
| 90 | : $self->{_detached_source}->result_class | ||||
| 91 | ; | ||||
| 92 | |||||
| 93 | Storable::nfreeze($to_serialize); | ||||
| 94 | } | ||||
| 95 | |||||
| 96 | =head2 STORABLE_thaw | ||||
| 97 | |||||
| 98 | Thaws frozen handle. Resets the internal schema reference to the package | ||||
| 99 | variable C<$thaw_schema>. The recommended way of setting this is to use | ||||
| 100 | C<< $schema->thaw($ice) >> which handles this for you. | ||||
| 101 | |||||
| 102 | =cut | ||||
| 103 | |||||
| 104 | sub STORABLE_thaw { | ||||
| 105 | my ($self, $cloning, $ice) = @_; | ||||
| 106 | %$self = %{ Storable::thaw($ice) }; | ||||
| 107 | |||||
| 108 | my $from_class = delete $self->{_frozen_from_class}; | ||||
| 109 | |||||
| 110 | if( $thaw_schema ) { | ||||
| 111 | $self->schema( $thaw_schema ); | ||||
| 112 | } | ||||
| 113 | elsif( my $rs = $from_class->result_source_instance ) { | ||||
| 114 | # in the off-chance we are using CDBI-compat and have leaked $schema already | ||||
| 115 | if( my $s = try { $rs->schema } ) { | ||||
| 116 | $self->schema( $s ); | ||||
| 117 | } | ||||
| 118 | else { | ||||
| 119 | $rs->source_name( $self->source_moniker ); | ||||
| 120 | $rs->{_detached_thaw} = 1; | ||||
| 121 | $self->_detached_source( $rs ); | ||||
| 122 | } | ||||
| 123 | } | ||||
| 124 | else { | ||||
| 125 | DBIx::Class::Exception->throw( | ||||
| 126 | "Thaw failed - original result class '$from_class' does not exist on this system" | ||||
| 127 | ); | ||||
| 128 | } | ||||
| 129 | } | ||||
| 130 | |||||
| 131 | =head1 FURTHER QUESTIONS? | ||||
| 132 | |||||
| 133 | Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>. | ||||
| 134 | |||||
| 135 | =head1 COPYRIGHT AND LICENSE | ||||
| 136 | |||||
| 137 | This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE> | ||||
| 138 | by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can | ||||
| 139 | redistribute it and/or modify it under the same terms as the | ||||
| 140 | L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>. | ||||
| 141 | |||||
| 142 | =cut | ||||
| 143 | |||||
| 144 | 1 | 4µs | 1 | 113µs | 1; # spent 113µs making 1 call to B::Hooks::EndOfScope::XS::__ANON__ |