| 1 | package VS::RuleEngine::TypeDecl; | ||||||||||
| 2 | |||||||||||
| 3 | 33 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 33 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 33 | ▶ | use Carp qw(croak); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 33 | ▶ | use Scalar::Util qw(blessed); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 229 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 10 | 229 | my ($pkg, $type, $defaults, @args) = @_; | |||||||||
| 11 | 229 | ▶ | $defaults = [] if !defined $defaults; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 12 | 229 | ▶ | $defaults = [$defaults] if ref $defaults ne 'ARRAY'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 13 | 229 | my $self = bless [$type, $defaults, \@args], $pkg; | |||||||||
| 14 | 229 | return $self; | |||||||||
| 15 | } | ||||||||||
| 16 | |||||||||||
| 17 | 184 | ▶ | sub instantiate { | ||||||||
|
Subroutine
instantiate: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 18 | 184 | my ($self, $engine) = @_; | |||||||||
| 19 | 184 | my $instance; | |||||||||
| 20 | |||||||||||
| 21 | 184 | ▶ | if (blessed $self->_pkg) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 1 | $instance = $self->_pkg; | |||||||||
| 23 | } | ||||||||||
| 24 | else { | ||||||||||
| 25 | 183 | my %defaults = map { %{$engine->get_defaults($_)} } @{$self->_defaults}; | |||||||||
| 26 | 183 | $instance = $self->_pkg->new(%defaults, @{$self->_args}); | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 184 | return $instance; | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | 394 | ▶ | sub _pkg { | ||||||||
|
Subroutine
_pkg: called CC=1 SCAR=0.0
| |||||||||||
| 33 | 394 | my $self = shift; | |||||||||
| 34 | 394 | return $self->[0]; | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | 183 | ▶ | sub _defaults { | ||||||||
|
Subroutine
_defaults: called CC=1 SCAR=0.0
| |||||||||||
| 38 | 183 | my $self = shift; | |||||||||
| 39 | 183 | return $self->[1]; | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 201 | ▶ | sub _args { | ||||||||
|
Subroutine
_args: called CC=1 SCAR=0.0
| |||||||||||
| 43 | 201 | my $self = shift; | |||||||||
| 44 | 201 | return $self->[2]; | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 33 | 1; | |||||||||
| 48 | __END__ | ||||||||||