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 | |
17 | =head1 NAME |
18 | |
19 | DBIx::Class::ResultSourceHandle |
20 | |
21 | =head1 DESCRIPTION |
22 | |
23 | This module removes fixed link between Rows/ResultSets and the actual source |
24 | objects, which gets round the following problems |
25 | |
26 | =over 4 |
27 | |
28 | =item * |
29 | |
30 | Needing to keep C<$schema> in scope, since any objects/result_sets |
31 | will have a C<$schema> object through their source handle |
32 | |
33 | =item * |
34 | |
35 | Large output when using Data::Dump(er) since this class can be set to |
36 | stringify to almost nothing |
37 | |
38 | =item * |
39 | |
7137528d |
40 | Closer 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 | |
50 | sub 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 |
60 | Resolve the moniker into the actual ResultSource object |
aec3eff1 |
61 | |
62 | =cut |
63 | |
3441fd57 |
64 | sub resolve { return $_[0]->schema->source($_[0]->source_moniker) } |
aec3eff1 |
65 | |
7137528d |
66 | =head2 STORABLE_freeze |
67 | |
68 | Freezes a handle. |
69 | |
70 | =cut |
71 | |
aec3eff1 |
72 | sub 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 | |
81 | Thaws frozen handle. |
82 | |
83 | =cut |
84 | |
aec3eff1 |
85 | sub STORABLE_thaw { |
86 | my ($self, $cloning,$ice) = @_; |
87 | %$self = %{ Storable::thaw($ice) }; |
88 | } |
89 | |
90 | 1; |