File Coverage

blib/lib/KiokuDB/TypeMap/Entry/DBIC/Row.pm
Criterion Covered Total %
statement 29 32 90.6
branch 1 2 50.0
condition n/a
subroutine 9 10 90.0
pod 0 1 0.0
total 39 45 86.6


line stmt bran cond sub pod time code
1             package KiokuDB::TypeMap::Entry::DBIC::Row;
2             BEGIN {
3 5     5   190 $KiokuDB::TypeMap::Entry::DBIC::Row::AUTHORITY = 'cpan:NUFFIN';
4             }
5             $KiokuDB::TypeMap::Entry::DBIC::Row::VERSION = '1.23';
6 5     5   30 use Moose;
  5         9  
  5         38  
7             # ABSTRACT: KiokuDB::TypeMap::Entry for DBIx::Class::Row objects.
8              
9 5     5   33882 use JSON;
  5         14  
  5         46  
10 5     5   734 use Scalar::Util qw(weaken);
  5         13  
  5         319  
11              
12 5     5   29 use namespace::autoclean;
  5         9  
  5         75  
13              
14             with qw(KiokuDB::TypeMap::Entry);
15              
16             has json => (
17             isa => "Object",
18             is => "ro",
19             default => sub { JSON->new },
20             );
21              
22             sub compile {
23 1     1 0 5452 my ( $self, $class ) = @_;
24              
25 1         36 my $json = $self->json;
26              
27             return KiokuDB::TypeMap::Entry::Compiled->new(
28             collapse_method => sub {
29 2     2   5094 my ( $collapser, @args ) = @_;
30              
31             $collapser->collapse_first_class(
32             sub {
33 2         481 my ( $collapser, %args ) = @_;
34              
35 2         8 my $obj = $args{object};
36              
37 2 50       6 if ( my @objs = values %{ $obj->{_kiokudb_column} } ) {
  2         14  
38 0         0 $collapser->visit(@objs);
39             }
40              
41 2         14 return $collapser->make_entry(
42             %args,
43             data => $obj,
44             );
45             },
46 2         19 @args,
47             );
48             },
49             expand_method => sub {
50 5     5   3198 my ( $linker, $entry ) = @_;
51              
52 5         109 my $obj = $entry->data;
53              
54 5         43 $linker->register_object( $entry => $obj );
55              
56 5         2797 return $obj;
57             },
58             id_method => sub {
59 2     2   625 my ( $self, $object ) = @_;
60              
61 2         12 return 'dbic:row:' . $json->encode([ $object->result_source->source_name, $object->id ]);
62             },
63             refresh_method => sub {
64 0     0     my ( $linker, $object, $entry, @args ) = @_;
65 0           $object->discard_changes; # FIXME avoid loading '$entry' alltogether
66             },
67 1         54 entry => $self,
68             class => $class,
69             );
70             }
71              
72             __PACKAGE__->meta->make_immutable;
73              
74             # ex: set sw=4 et:
75              
76             __PACKAGE__
77              
78             __END__
79              
80             =pod
81              
82             =encoding UTF-8
83              
84             =head1 NAME
85              
86             KiokuDB::TypeMap::Entry::DBIC::Row - KiokuDB::TypeMap::Entry for DBIx::Class::Row objects.
87              
88             =head1 VERSION
89              
90             version 1.23
91              
92             =head1 DESCRIPTION
93              
94             L<DBIx::Class::Row> objects are resolved symbolically using the special ID
95             format:
96              
97             dbic:row:$json
98              
99             The C<$json> string is a serialization of:
100              
101             [ $result_source_name, @primary_key_values ]
102              
103             The row objects are not actually written to the KiokuDB storage, as they are
104             already present in the other tables.
105              
106             Looking up an object with such an ID is a dynamic lookup that delegates to the
107             L<DBIx::Class::Schema> and resultsets.
108              
109             =for Pod::Coverage compile
110              
111             =head1 AUTHOR
112              
113             Yuval Kogman <nothingmuch@woobling.org>
114              
115             =head1 COPYRIGHT AND LICENSE
116              
117             This software is copyright (c) 2014 by Yuval Kogman, Infinity Interactive.
118              
119             This is free software; you can redistribute it and/or modify it under
120             the same terms as the Perl 5 programming language system itself.
121              
122             =cut