File Coverage

blib/lib/KiokuDB/TypeMap/Entry/DBIC/ResultSource.pm
Criterion Covered Total %
statement 24 25 96.0
branch 1 2 50.0
condition n/a
subroutine 8 9 88.8
pod 0 1 0.0
total 33 37 89.1


line stmt bran cond sub pod time code
1             package KiokuDB::TypeMap::Entry::DBIC::ResultSource;
2             BEGIN {
3 5     5   217 $KiokuDB::TypeMap::Entry::DBIC::ResultSource::AUTHORITY = 'cpan:NUFFIN';
4             }
5             $KiokuDB::TypeMap::Entry::DBIC::ResultSource::VERSION = '1.23';
6 5     5   36 use Moose;
  5         14  
  5         43  
7             # ABSTRACT: KiokuDB::TypeMap::Entry for DBIx::Class::ResultSource objects.
8              
9 5     5   37312 use Scalar::Util qw(weaken refaddr);
  5         15  
  5         393  
10              
11 5     5   37 use namespace::autoclean;
  5         13  
  5         58  
12              
13             with qw(KiokuDB::TypeMap::Entry);
14              
15             sub compile {
16 2     2 0 8764 my ( $self, $class ) = @_;
17              
18             return KiokuDB::TypeMap::Entry::Compiled->new(
19             collapse_method => sub {
20 1     1   593 my ( $collapser, @args ) = @_;
21              
22             $collapser->collapse_first_class(
23             sub {
24 1         143 my ( $collapser, %args ) = @_;
25              
26 1 50       23 if ( refaddr($collapser->backend->schema) == refaddr($args{object}->schema) ) {
27 1         14 return $collapser->make_entry(
28             %args,
29             data => undef,
30             meta => {
31             immortal => 1,
32             },
33             );
34             } else {
35 0         0 croak("Referring to foreign DBIC schemas is unsupported");
36             }
37             },
38 1         11 @args,
39             );
40             },
41             expand_method => sub {
42 1     1   355 my ( $linker, $entry ) = @_;
43              
44 1         21 my $schema = $linker->backend->schema;
45              
46 1         18 my $rs = $schema->source(substr($entry->id, length('dbic:schema:rs:')));
47              
48 1         56 $linker->register_object( $entry => $rs, immortal => 1 );
49              
50 1         411 return $rs;
51             },
52             id_method => sub {
53 1     1   437 my ( $self, $object ) = @_;
54              
55 1         113 return 'dbic:schema:rs:' . $object->source_name;
56             },
57       0     refresh_method => sub { },
58 2         95 entry => $self,
59             class => $class,
60             );
61             }
62              
63              
64             __PACKAGE__->meta->make_immutable;
65              
66             # ex: set sw=4 et:
67              
68             __PACKAGE__
69              
70             __END__
71              
72             =pod
73              
74             =encoding UTF-8
75              
76             =head1 NAME
77              
78             KiokuDB::TypeMap::Entry::DBIC::ResultSource - KiokuDB::TypeMap::Entry for DBIx::Class::ResultSource objects.
79              
80             =head1 VERSION
81              
82             version 1.23
83              
84             =head1 DESCRIPTION
85              
86             This tyepmap entry resolves result source handles symbolically by name.
87              
88             References to the handle receive a special ID in the form:
89              
90             dbic:schema:rs:$name
91              
92             and are not actually written to storage.
93              
94             Looking up such an ID causes the backend to dynamically search for such a
95             resultset in the L<DBIx::Class::Schema>.
96              
97             =for Pod::Coverage compile
98              
99             =head1 AUTHOR
100              
101             Yuval Kogman <nothingmuch@woobling.org>
102              
103             =head1 COPYRIGHT AND LICENSE
104              
105             This software is copyright (c) 2014 by Yuval Kogman, Infinity Interactive.
106              
107             This is free software; you can redistribute it and/or modify it under
108             the same terms as the Perl 5 programming language system itself.
109              
110             =cut