line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::Cache::Role::GetDefault; |
2
|
7
|
|
|
7
|
|
3950
|
use Mojo::Base -role; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
44
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
with 'Mojo::Cache::Role::Exists'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
requires qw(get set); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has 'default'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
around get => sub { |
13
|
|
|
|
|
|
|
my $orig = shift; |
14
|
|
|
|
|
|
|
my $self = shift; |
15
|
|
|
|
|
|
|
my $key = shift; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
if ((not @_ and not defined $self->default) or $self->exists($key)) { |
18
|
|
|
|
|
|
|
return $self->$orig($key); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $default = @_ ? $_[0] : $self->default; |
22
|
|
|
|
|
|
|
my $value = ref $default eq 'CODE' ? do { local $_ = $key; $default->($key) } : $default; |
23
|
|
|
|
|
|
|
$self->set($key, $value); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
return $value; |
26
|
|
|
|
|
|
|
}; |
27
|
|
|
|
|
|
|
|
28
|
6
|
|
|
6
|
1
|
19
|
sub clear_default { $_[0]->default(undef) } |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
1; |
31
|
|
|
|
|
|
|
__END__ |