1 package DBIx::Class::ResultSourceHandle;
8 use base qw/DBIx::Class/;
11 # on some RH perls the following line causes serious performance problem
12 # see https://bugzilla.redhat.com/show_bug.cgi?id=196836
13 q/""/ => sub { __PACKAGE__ . ":" . shift->source_moniker; },
16 __PACKAGE__->mk_group_accessors('simple' => qw/schema source_moniker/);
18 # Schema to use when thawing.
23 DBIx::Class::ResultSourceHandle - Decouple Rows/ResultSets objects from their Source objects
27 This module removes fixed link between Rows/ResultSets and the actual source
28 objects, which gets round the following problems
34 Needing to keep C<$schema> in scope, since any objects/result_sets
35 will have a C<$schema> object through their source handle
39 Large output when using Data::Dump(er) since this class can be set to
40 stringify to almost nothing
44 Closer to being able to do a Serialize::Storable that doesn't require class-based connections
55 my ($class, $data) = @_;
57 $class = ref $class if ref $class;
64 Resolve the moniker into the actual ResultSource object
68 sub resolve { return $_[0]->schema->source($_[0]->source_moniker) }
70 =head2 STORABLE_freeze
77 my ($self, $cloning) = @_;
79 my $to_serialize = { %$self };
81 delete $to_serialize->{schema};
82 $to_serialize->{_frozen_from_class} = $self->schema->class($self->source_moniker);
84 return (Storable::freeze($to_serialize));
89 Thaws frozen handle. Resets the internal schema reference to the package
90 variable C<$thaw_schema>. The recomened way of setting this is to use
91 C<< $schema->thaw($ice) >> which handles this for you.
97 my ($self, $cloning, $ice) = @_;
98 %$self = %{ Storable::thaw($ice) };
100 my $class = delete $self->{_frozen_from_class};
102 $self->{schema} = $thaw_schema;
105 my $rs = $class->result_source_instance;
106 $self->{schema} = $rs->schema if $rs;
109 carp "Unable to restore schema. Look at 'freeze' and 'thaw' methods in DBIx::Class::Schema."
110 unless $self->{schema};
115 Ash Berlin C<< <ash@cpan.org> >>