line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package KiokuDB::Meta::Instance; |
4
|
3
|
|
|
3
|
|
15
|
use Moose::Role; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
24
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
13017
|
use namespace::clean -except => 'meta'; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
29
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
around 'get_slot_value' => sub { |
9
|
|
|
|
|
|
|
my ( $next, $self, $instance, $slot, @args ) = @_; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $value = $self->$next($instance, $slot, @args); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
if ( ref($value) eq 'KiokuDB::Thunk' ) { |
14
|
|
|
|
|
|
|
$value = $value->vivify($instance); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
return $value; |
18
|
|
|
|
|
|
|
}; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
around 'inline_get_slot_value' => sub { |
21
|
|
|
|
|
|
|
my ( $next, $self, $instance_expr, $slot_expr, @args ) = @_; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $get_expr = $self->$next($instance_expr, $slot_expr, @args); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
return 'do { |
26
|
|
|
|
|
|
|
my $value = ' . $get_expr . '; |
27
|
|
|
|
|
|
|
if ( ref($value) eq "KiokuDB::Thunk" ) { |
28
|
|
|
|
|
|
|
$value = $value->vivify(' . $instance_expr . '); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
$value; |
31
|
|
|
|
|
|
|
}' |
32
|
|
|
|
|
|
|
}; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
__PACKAGE__ |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
__END__ |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=pod |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 NAME |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
KiokuDB::Meta::Instance - L<Moose::Meta::Instnace> level support for lazy loading. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 SYNOPSIS |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# use KiokuDB::Meta::Attribute::Lazy |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 DESCRIPTION |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
This role is applied to the meta instance class automatically by |
51
|
|
|
|
|
|
|
L<KiokuDB::Class>. When it finds L<KiokuDB::Thunk> objects in the low level |
52
|
|
|
|
|
|
|
attribute storage it will cause them to be loaded. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
This allows your L<Moose::Meta::Attributes> to remain oblivious to the fact |
55
|
|
|
|
|
|
|
that the value is deferred, making sure that all the type constraints, lazy |
56
|
|
|
|
|
|
|
defaults, and various other L<Moose> features continue to work normally. |
57
|
|
|
|
|
|
|
|