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