1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
package DBIx::Class::ResultSourceHandle;
use strict;
use warnings;
use Storable;
use base qw/DBIx::Class/;
use overload
# on some RH perls the following line causes serious performance problem
# see https://bugzilla.redhat.com/show_bug.cgi?id=196836
q/""/ => sub { __PACKAGE__ . ":" . shift->source_moniker; },
fallback => 1;
__PACKAGE__->mk_group_accessors('simple' => qw/schema source_moniker/);
# Schema to use when thawing.
our $thaw_schema;
=head1 NAME
DBIx::Class::ResultSourceHandle
=head1 DESCRIPTION
This module removes fixed link between Rows/ResultSets and the actual source
objects, which gets round the following problems
=over 4
=item *
Needing to keep C<$schema> in scope, since any objects/result_sets
will have a C<$schema> object through their source handle
=item *
Large output when using Data::Dump(er) since this class can be set to
stringify to almost nothing
=item *
Closer to being able to do a Serialize::Storable that doesn't require class-based connections
=back
=head1 METHODS
=head2 new
=cut
sub new {
my ($class, $data) = @_;
$class = ref $class if ref $class;
bless $data, $class;
}
=head2 resolve
Resolve the moniker into the actual ResultSource object
=cut
sub resolve { return $_[0]->schema->source($_[0]->source_moniker) }
=head2 STORABLE_freeze
Freezes a handle.
=cut
sub STORABLE_freeze {
my ($self, $cloning) = @_;
my $to_serialize = { %$self };
delete $to_serialize->{schema};
return (Storable::freeze($to_serialize));
}
=head2 STORABLE_thaw
Thaws frozen handle. Resets the internal schema reference to the package
variable C<$thaw_schema>. The recomened way of setting this is to use
C<$schema->thaw($ice)> which handles this for you.
=cut
sub STORABLE_thaw {
my ($self, $cloning,$ice) = @_;
%$self = %{ Storable::thaw($ice) };
$self->{schema} = $thaw_schema;
}
=head1 AUTHOR
Ash Berlin C<< <ash@cpan.org> >>
=cut
1;
|