Changed row and rs objects to not have direct handle to a source, instead a
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / ResultSourceHandle.pm
1 package DBIx::Class::ResultSourceHandle;
2
3 use strict;
4 use warnings;
5 use Storable;
6
7 use base qw/DBIx::Class/;
8
9 use overload
10     q/""/ => sub { __PACKAGE__ . ":" . shift->source_monkier; },
11     fallback => 1;
12
13 __PACKAGE__->mk_group_accessors('simple' => qw/schema source_monkier/);
14
15 =head1 NAME
16
17 DBIx::Class::ResultSourceHandle
18
19 =head1 DESCRIPTION
20
21 This module removes fixed link between Rows/ResultSets and the actual source
22 objects, which gets round the following problems
23
24 =over 4
25
26 =item *
27
28 Needing to keep C<$schema> in scope, since any objects/result_sets
29 will have a C<$schema> object through their source handle
30
31 =item *
32
33 Large output when using Data::Dump(er) since this class can be set to
34 stringify to almost nothing
35
36 =item *
37
38 Closer to being aboe to do a Serialize::Storable that doesn't require class-based connections
39
40 =back
41
42 =head1 METHODS
43
44 =head2 new
45
46 =cut
47
48 sub new {
49     my ($class, $data) = @_;
50
51     $class = ref $class if ref $class;
52
53     bless $data, $class;
54 }
55
56 =head2 resolve
57
58 Resolve the monkier into the actual ResultSource object
59
60 =cut
61
62 sub resolve { return $_[0]->schema->source($_[0]->source_monkier) }
63
64 sub STORABLE_freeze {
65     my ($self, $cloning) = @_;
66     my $to_serialize = { %$self };
67     delete $to_serialize->{schema};
68     return (Storable::freeze($to_serialize));
69 }
70
71 sub STORABLE_thaw {
72     my ($self, $cloning,$ice) = @_;
73     %$self = %{ Storable::thaw($ice) };
74 }
75
76 1;