File Coverage

blib/lib/KiokuDB/TypeMap/Entry/DBIC/Schema.pm
Criterion Covered Total %
statement 23 24 95.8
branch 1 2 50.0
condition n/a
subroutine 8 9 88.8
pod 0 1 0.0
total 32 36 88.8


line stmt bran cond sub pod time code
1             package KiokuDB::TypeMap::Entry::DBIC::Schema;
2             BEGIN {
3 5     5   222 $KiokuDB::TypeMap::Entry::DBIC::Schema::AUTHORITY = 'cpan:NUFFIN';
4             }
5             $KiokuDB::TypeMap::Entry::DBIC::Schema::VERSION = '1.23';
6 5     5   32 use Moose;
  5         13  
  5         40  
7             # ABSTRACT: KiokuDB::TypeMap::Entry for DBIx::Class::Schema objects.
8              
9 5     5   32791 use Scalar::Util qw(weaken refaddr);
  5         13  
  5         357  
10              
11 5     5   36 use namespace::autoclean;
  5         36  
  5         54  
12              
13             with qw(KiokuDB::TypeMap::Entry);
14              
15             sub compile {
16 2     2 0 2757 my ( $self, $class ) = @_;
17              
18             return KiokuDB::TypeMap::Entry::Compiled->new(
19             collapse_method => sub {
20 1     1   554 my ( $collapser, @args ) = @_;
21              
22             $collapser->collapse_first_class(
23             sub {
24 1         215 my ( $collapser, %args ) = @_;
25              
26 1 50       24 if ( refaddr($collapser->backend->schema) == refaddr($args{object}) ) {
27 1         8 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         9 @args,
39             );
40             },
41             expand_method => sub {
42 1     1   311 my ( $linker, $entry ) = @_;
43              
44 1         20 my $schema = $linker->backend->schema;
45              
46 1         5 $linker->register_object( $entry => $schema, immortal => 1 );
47              
48 1         450 return $schema;
49             },
50             id_method => sub {
51 1     1   269 my ( $self, $object ) = @_;
52              
53 1         2 return 'dbic:schema'; # singleton
54             },
55       0     refresh_method => sub { },
56 2         75 entry => $self,
57             class => $class,
58             );
59             }
60              
61             __PACKAGE__->meta->make_immutable;
62              
63             # ex: set sw=4 et:
64              
65             __PACKAGE__
66              
67             __END__
68              
69             =pod
70              
71             =encoding UTF-8
72              
73             =head1 NAME
74              
75             KiokuDB::TypeMap::Entry::DBIC::Schema - KiokuDB::TypeMap::Entry for DBIx::Class::Schema objects.
76              
77             =head1 VERSION
78              
79             version 1.23
80              
81             =head1 DESCRIPTION
82              
83             This typemap entry handles references to L<DBIx::Class::Schema> as a scoped
84             singleton.
85              
86             The ID of the schema is always C<dbic:schema>.
87              
88             References to L<DBIx::Class::Schema> objects which are not a part of the
89             underlying L<DBIx::Class> layout are currently not supported, but may be in the
90             future.
91              
92             =for Pod::Coverage compile
93              
94             =head1 AUTHOR
95              
96             Yuval Kogman <nothingmuch@woobling.org>
97              
98             =head1 COPYRIGHT AND LICENSE
99              
100             This software is copyright (c) 2014 by Yuval Kogman, Infinity Interactive.
101              
102             This is free software; you can redistribute it and/or modify it under
103             the same terms as the Perl 5 programming language system itself.
104              
105             =cut