File Coverage

blib/lib/Aspect/Library/Singleton.pm
Criterion Covered Total %
statement 24 24 100.0
branch 3 4 75.0
condition 1 3 33.3
subroutine 7 7 100.0
pod 0 1 0.0
total 35 39 89.7


line stmt bran cond sub pod time code
1             package Aspect::Library::Singleton;
2              
3 2     2   1178 use strict;
  2         3  
  2         47  
4 2     2   6 use warnings;
  2         3  
  2         45  
5 2     2   303 use Aspect::Modular ();
  2         5  
  2         29  
6 2     2   7 use Aspect::Advice::Before ();
  2         2  
  2         19  
7 2     2   5 use Aspect::Pointcut::Call ();
  2         3  
  2         280  
8              
9             our $VERSION = '0.97_06';
10             our @ISA = 'Aspect::Modular';
11              
12             my %CACHE = ();
13              
14             sub get_advice {
15 2     2 0 3 my $self = shift;
16             Aspect::Advice::Around->new(
17             lexical => $self->lexical,
18             pointcut => Aspect::Pointcut::Call->new(shift),
19             code => sub {
20 2     2   37 my $class = $_->self;
21 2   33     9 $class = ref $class || $class;
22 2 100       3 if ( exists $CACHE{$class} ) {
23 1         4 $_->return_value($CACHE{$class});
24             } else {
25 1         6 $_->proceed;
26 1 50       10 unless ( $_->exception ) {
27 1         4 $CACHE{$class} = $_->return_value;
28             }
29             }
30             },
31 2         20 );
32             }
33              
34             1;
35              
36             __END__