KiokuDB/Meta/Attribute/Lazy.pm

filter: Statementstmt 68.7% 11 / 16 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 3 / 5 Podpod 0.0% 0 / 1 totaltotal 58.3% 14 / 24 CC 2 SCAR 10.4
CC
2
Cov
61%
__ANON__
6.0
register_implementation
2.0
BEGIN
1.0
CRAP 2.8
« KiokuDB/Test/Fixture/TXN.pm ↑ Summary KiokuDB/TypeMap/Entry/Callback.pm »
1 #!/usr/bin/perl
2  
3 package KiokuDB::Meta::Attribute::Lazy;
4 3 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use Moose::Util qw(does_role);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use namespace::clean -except => 'meta';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 0 ▶sub Moose::Meta::Attribute::Custom::Trait::KiokuDB::Lazy::register_implementation { __PACKAGE__ }
Subroutine register_implementation: not called CC=1 SCAR=6.9
Pod undocumented
11  
12 before attach_to_class => sub {
13 0 ▶ my ( $self, $class ) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
14  
15 0 my $mi = $class->get_meta_instance;
16  
17 0 ▶ unless ( does_role( $mi, "KiokuDB::Meta::Instance" ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (does_role($mi, "KiokuDB::Meta::Instance")) 0 0 0
18 0 $self->throw_error("Can't attach to a class whose meta instance doesn't do KiokuDB::Meta::Instance", data => $class );
19 }
20 3 };
21  
22 3 __PACKAGE__
23  
24 __END__
25  
26 =pod
27  
28 =head1 NAME
29  
30 KiokuDB::Meta::Attribute::Lazy - Trait for lazy loaded attributes
31  
32 =head1 SYNOPSIS
33  
34 # in your class:
35  
36 package Foo;
37 use KiokuDB::Class;
38  
39 has bar => (
40 traits => [qw(KiokuDB::Lazy)],
41 isa => "Bar",
42 is => "ro",
43 );
44  
45  
46  
47 # Later:
48  
49 my $foo = $dir->lookup($id);
50  
51 # bar is not yet loaded, it will be lazily fetched during this call:
52 $foo->bar;
53  
54 =head1 DESCRIPTION
55  
56 This L<Moose::Meta::Attribute> trait provides lazy loading on a per field basis
57 for objects stored in L<KiokuDB>.
58  
59 Instead of using proxy objects with AUTOLOAD, overloading, or similar hacks,
60 you can declaratively specify which attributes you want to make lazy, and this
61 will be done cleanly through the MOP.
62  
63 This is implemented by using a placeholder object, L<KiokuDB::Thunk> which
64 contains references to the ID and the linker, and L<KiokuDB::Meta::Instance>
65 will know to replace the placeholder with the actual loaded object when it is
66 fetched from the object by an accessor.
67  
68 =cut
69  
70  
« KiokuDB/Test/Fixture/TXN.pm ↑ Summary KiokuDB/TypeMap/Entry/Callback.pm »