| 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
| |||||||||||||||||||||||||||||||||||||
| 27 | 0 | my $config = $self->find_config($type, $name); | |||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | if ($config) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 29 | 0 | $resource = $self->construct_resource($name, $config, @args); | |||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | if ($resource) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 31 | 0 | $self->resources->{$type}->{$name} = $resource; | |||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | if ($resource && $resource->can('ACCEPT_CONTEXT')) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$resource and $resource->can("ACCEPT_CONTEXT")
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")
| |||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if ($config) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||
| 70 | 0 | $pkg = join('::', blessed $self, $pkg); | |||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | if (! Class::MOP::is_class_loaded($pkg)) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 73 | 0 | eval "require $pkg"; | |||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | die if $@; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | my $constructor = $config->{constructor} || 'new'; | ||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$config->{'constructor'} || 'new'
MC/DC0%0/1
$config->{'constructor'} || 'new'
$config->{'constructor'}
Truth table0%0/2
A
A= $config->{'constructor'}
| |||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | my $args = $config->{args} || {}; | ||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$config->{'args'} || {}
MC/DC0%0/1
$config->{'args'} || {}
$config->{'args'}
Truth table0%0/2
A
A= $config->{'args'}
| |||||||||||||||||||||||||||||||||||||
| 79 | 0 | my $deref = $config->{deref}; | |||||||||||||||||||||||||||||||||||
| 80 | 0 | my $ref = ref $args; | |||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | $pkg->$constructor( ($deref && $ref) ? | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/3
$deref and $ref
MC/DC0%0/2
$deref and $ref
$deref
$ref
Truth table0%0/3
A and B
A= $derefB= $ref
| |||||||||||||||||||||||||||||||||||||
| 82 | ($ref eq 'ARRAY' ? @$args : | ||||||||||||||||||||||||||||||||||||
| 83 | $ref eq 'HASH' ? %$args : $args) : | ||||||||||||||||||||||||||||||||||||
| 84 | $args | ||||||||||||||||||||||||||||||||||||
| 85 | ); | ||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||
| 88 | 2 | 1; | |||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||
| 90 | __END__ | ||||||||||||||||||||||||||||||||||||