ResourceSet.pm

filter: Statementstmt 17.0% 7 / 41 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 16.6% 1 / 6 Podpod 100% 3 / 3 totaltotal 11.9% 11 / 92 CC 18 SCAR 41.3
CC
18
Cov
9%
construct_resource
110.0
resource
42.0
find_config
20.0
CRAP 62.5
↑ Summary ResourceSet/Adaptor.pm »
1 # $Id: /mirror/coderepos/lang/perl/Data-ResourceSet/trunk/lib/Data/ResourceSet.pm 54071 2008-05-19T06:52:45.149433Z daisuke $
2  
3 package Data::ResourceSet;
4 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 has 'resources' => (
7 is => 'rw',
8 isa => 'HashRef',
9 required => 1,
10 0 ▶ default => sub { +{} }
Subroutine __ANON__: not called CC=1 SCAR=6.9
11 2 );
12  
13 has 'resources_config' => (
14 is => 'rw',
15 isa => 'HashRef',
16 0 ▶ default => sub { +{} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
17 2 );
18  
19 2 our $VERSION = '0.00003';
20  
21 sub resource
22 0 ▶{
Subroutine resource: not called CC=6 SCAR=37.4
Pod documented
23 0 my ($self, $type, $name, @args) = @_;
24  
25 0 my $resource = $self->resources->{$type}->{$name};
26 0 ▶ if (! $resource) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($resource) 0 0 0
27 0 my $config = $self->find_config($type, $name);
28 0 ▶ if ($config) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config) 0 0 0
29 0 $resource = $self->construct_resource($name, $config, @args);
30 0 ▶ if ($resource) {
Branch: 1 branch
BranchTrueFalseTotal
if ($resource) 0 0 0
31 0 $self->resources->{$type}->{$name} = $resource;
32 }
33 }
34 }
35  
36 0 ▶ if ($resource && $resource->can('ACCEPT_CONTEXT')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($resource and $resource->can("ACCEPT_CONTEXT")) 0 0 0
Condition0%0/3
$resource and $resource->can("ACCEPT_CONTEXT")
!ll&&!rl&&r
000
MC/DC0%0/2
$resource and $resource->can("ACCEPT_CONTEXT")
$resource $resource->can("ACCEPT_CONTEXT")
Truth table0%0/3
A and B
A= $resourceB= $resource->can("ACCEPT_CONTEXT")
ABresult
0X0
100
111
37 0 return $resource->ACCEPT_CONTEXT($self, @args);
38 }
39  
40 0 return $resource;
41 }
42  
43 sub find_config
44 0 ▶{
Subroutine find_config: not called CC=4 SCAR=30.0
Pod documented
45 0 my ($self, $type, $name) = @_;
46  
47 0 my $config;
48 # find a per-instance config
49 0 $config = $self->resources_config->{$type}->{$name};
50 0 ▶ if ($config) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config) 0 0 0
51 0 return $config;
52 }
53  
54 # find a per-package config
55 $config = $self->can('config') ?
56 0 ▶ $self->config('resources')->{$type}->{$name} : ();
Branch: 1 branch
BranchTrueFalseTotal
$self->can('config') ? : 0 0 0
57 0 ▶ if ($config) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config) 0 0 0
58 0 return $config;
59 }
60  
61 0 return ();
62 }
63  
64 sub construct_resource
65 0 ▶{
Subroutine construct_resource: not called CC=10 SCAR=47.0
Pod documented
66 0 my ($self, $name, $config, @args) = @_;
67  
68 0 my $pkg = $config->{module};
69 0 ▶ if ($pkg !~ s/^\+//) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pkg =~ s/^\+//) 0 0 0
70 0 $pkg = join('::', blessed $self, $pkg);
71 }
72 0 ▶ if (! Class::MOP::is_class_loaded($pkg)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (Class::MOP::is_class_loaded($pkg)) 0 0 0
73 0 eval "require $pkg";
74 0 ▶ die if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
75 }
76  
77 0 ▶ my $constructor = $config->{constructor} || 'new';
Condition0%0/2
$config->{'constructor'} || 'new'
l!l
00
MC/DC0%0/1
$config->{'constructor'} || 'new'
$config->{'constructor'}
Truth table0%0/2
A
A= $config->{'constructor'}
Aresult
11
00
78 0 ▶ my $args = $config->{args} || {};
Condition0%0/2
$config->{'args'} || {}
l!l
00
MC/DC0%0/1
$config->{'args'} || {}
$config->{'args'}
Truth table0%0/2
A
A= $config->{'args'}
Aresult
11
00
79 0 my $deref = $config->{deref};
80 0 my $ref = ref $args;
81 0 ▶ $pkg->$constructor( ($deref && $ref) ?
Branch: 3 branches
BranchTrueFalseTotal
$deref && $ref ? : 0 0 0
$ref eq 'ARRAY' ? : 0 0 0
$ref eq 'HASH' ? : 0 0 0
Condition0%0/3
$deref and $ref
!ll&&!rl&&r
000
MC/DC0%0/2
$deref and $ref
$deref $ref
Truth table0%0/3
A and B
A= $derefB= $ref
ABresult
0X0
100
111
82 ($ref eq 'ARRAY' ? @$args :
83 $ref eq 'HASH' ? %$args : $args) :
84 $args
85 );
86 }
87  
88 2 1;
89  
90 __END__
↑ Summary ResourceSet/Adaptor.pm »