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