| 1 | package Aion::Pleroma; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # Контейнер для эонов (сервисов) | ||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use common::sense; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Aion::Env AION_PLEROMA_INI => (default => 'etc/annotation/eon.ann'); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Aion::Env AION_PLEROMA_AUTOWARE => (default => 1); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Aion::Env::Etc EON => (default => {}, key => 'aion.eon'); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Aion; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | # Файл с аннотациями | ||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | has ini => (is => 'ro', isa => Maybe[Str], default => AION_PLEROMA_INI); | |||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | # Конфигурация: ключ => хеш-описание эона (class, method, arguments, calls) | ||||||||||||||||||||||||||||||||||||||||||
| 16 | 8 | ▶ | has pleroma => (is => 'ro?!', isa => HashRef, default => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=10 SCAR=24.5
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 8 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 8 | $self->{pleroma} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 8 | $self->autoware('Aion::Pleroma'); | |||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | for my $key (keys %{&EON}) { $self->autoware(EON->{$key}, $key) } | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 8 | ▶ | return $self->pleroma unless defined $self->ini and -e $self->ini; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->ini and -e $self->ini
MC/DC50%1/2
defined $self->ini and -e $self->ini
defined $self->ini
-e $self->ini
Truth table66%2/3
A and B
A= defined $self->iniB= -e $self->ini
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | open my $f, '<:encoding(UTF-8)', $self->ini or die "Not open ${\$self->ini}: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 7 | ▶ | while(<$f>) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | do { close $f; die "${\$self->ini} corrupt at line $.: $_" } unless /^([\w:]+)#(\w*),\d+=(.*)$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 21 | my ($pkg, $sub, $key) = ($1, $2, $3); | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 21 | ▶ | $key = $key ne ""? $key: ($sub? "$pkg#$sub": $pkg); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 21 | ▶ | $self->autoware(+{class => $pkg, method => $sub || 'new'}, $key); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$sub || 'new'
MC/DC100%1/1
$sub || 'new'
$sub
Truth table100%2/2
A
A= $sub
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 7 | close $f; | |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 7 | $self->pleroma | |||||||||||||||||||||||||||||||||||||||||
| 37 | 2 | }); | |||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | # Совокупность порождённых эонов-сервисов | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 11 | ▶ | has eon => (is => 'ro', isa => HashRef[Object], lazy => 0, default => sub { +{'Aion::Pleroma' => shift} }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | # Получить эон из контейнера | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 21 | ▶ | sub get { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 21 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 21 | my $eon = $self->{eon}{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 21 | ▶ | return $eon if $eon; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 17 | my $config = _hash_config($self->pleroma->{$key}); | |||||||||||||||||||||||||||||||||||||||||
| 50 | 17 | ▶ | if($config) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 12 | $self->{eon}{$key} = $self->_build($key, $config); | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | elsif(AION_PLEROMA_AUTOWARE and $key =~ /^([\w:]+)(#\w+)?$/ and _find_pm($1)) { $self->autoware($key)->get($key) } | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$key =~ /^([\w:]+)(#\w+)?$/u and _find_pm($1)
MC/DC0%0/2
$key =~ /^([\w:]+)(#\w+)?$/u and _find_pm($1)
$key =~ /^([\w:]+)(#\w+)?$/u
_find_pm($1)
Truth table66%2/3
A and B
A= $key =~ /^([\w:]+)(#\w+)?$/uB= _find_pm($1)
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 5 | else { undef } | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | # Получить эон из контейнера или исключение, если его там нет | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 11 | ▶ | sub resolve { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resolve: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 11 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 11 | ▶ | $self->get($key) // die "$key is'nt eon!"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->get($key) // die("$key is'nt eon!")
MC/DC0%0/1
$self->get($key) // die("$key is'nt eon!")
$self->get($key)
Truth table50%1/2
A
A= $self->get($key)
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | # Добавить в плерому эон. $config — строка 'класс#метод' либо хеш (class, method, arguments, calls) | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 37 | ▶ | sub autoware { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
autoware: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 37 | my ($self, $config, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 37 | ▶ | $config = _hash_config($config) unless ref $config eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 37 | ▶ | my $pkg = $config->{class} // die "autoware: class is undef!"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$config->{"class"} // die("autoware: class is undef!")
MC/DC0%0/1
$config->{"class"} // die("autoware: class is undef!")
$config->{"class"}
Truth table50%1/2
A
A= $config->{"class"}
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 37 | ▶ | my $sub = $config->{method} // 'new'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$config->{"method"} // "new"
MC/DC100%1/1
$config->{"method"} // "new"
$config->{"method"}
Truth table100%2/2
A
A= $config->{"method"}
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 37 | my $action = "$pkg#$sub"; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 37 | ▶ | $key //= $sub eq 'new'? $pkg: $action; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$key //= $sub eq "new" ? $pkg : $action
MC/DC0%0/2
$key //= $sub eq "new" ? $pkg : $action
$key
$sub eq "new" ? $pkg : $action
Truth table66%2/3
A //= B
A= $keyB= $sub eq "new" ? $pkg : $action
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 37 | my $pleroma = $self->pleroma; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 37 | my $exists = $pleroma->{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 37 | ▶ | if(defined $exists) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 3 | my $str = _string_config($exists); | |||||||||||||||||||||||||||||||||||||||||
| 78 | 3 | ▶ | die "Added eon $key twice, with $action ne $str" if $str ne $action; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 2 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 34 | $pleroma->{$key} = $config; | |||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | # При добавлении нового ключа проверяем, не замкнулся ли цикл ссылок | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 34 | $self->_check_cycle($key); | |||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 33 | $self | |||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | # Пройти по @-ссылкам от $key и выбросить исключение, если цепочка замкнулась на себя | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 34 | ▶ | sub _check_cycle { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_cycle: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 34 | my ($self, $start) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 34 | my %visiting; | |||||||||||||||||||||||||||||||||||||||||
| 95 | my $walk; | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 37 | ▶ | $walk = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 37 | my ($key, $path) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | die "Circular eon dependency: " . join(' -> ', @$path, $key) | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 37 | ▶ | if exists $visiting{$key}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 36 | my $pleroma = $self->pleroma; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 36 | ▶ | my $conf = _hash_config($pleroma->{$key}) or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 35 | $visiting{$key} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 106 | 35 | $walk->($_, [@$path, $key]) for _conf_refs($conf); | |||||||||||||||||||||||||||||||||||||||||
| 107 | 33 | delete $visiting{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 34 | }; | |||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 34 | $walk->($start, []); | |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | # Ключи эонов, на которые ссылается конфигурация (значения, начинающиеся с '@') | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 35 | ▶ | sub _conf_refs { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_conf_refs: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 35 | my ($conf) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 35 | ▶ | return () unless $conf; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 35 | my @refs; | |||||||||||||||||||||||||||||||||||||||||
| 118 | my $collect; | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 120 | ▶ | $collect = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=20.9
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 120 | my ($v) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 120 | ▶ | if(defined $v && !ref $v) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
defined $v and not ref $v
MC/DC50%1/2
defined $v and not ref $v
defined $v
not ref $v
Truth table66%2/3
A and not(B)
A= defined $vB= not ref $v
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 78 | ▶ | push @refs, $1 if $v =~ /^@(.+)/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 6 | elsif(ref $v eq 'ARRAY') { $collect->($_) for @$v } | |||||||||||||||||||||||||||||||||||||||||
| 125 | 36 | elsif(ref $v eq 'HASH') { $collect->($_) for values %$v } | |||||||||||||||||||||||||||||||||||||||||
| 126 | 35 | }; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 35 | $collect->($conf); | |||||||||||||||||||||||||||||||||||||||||
| 128 | @refs | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 35 | } | |||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | # Построить эон из хеш-описания: class, method, arguments, calls | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 12 | ▶ | sub _build { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build: called CC=9 SCAR=22.9
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 12 | my ($self, $key, $conf) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | 12 | ▶ | my $pkg = $conf->{class} // ($key =~ /^[\w:]+$/a ? $key : undef) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition40%2/5
($conf->{"class"} // ($key =~ /^[\w:]+$/a ? $key : undef)) // die("Eon ${key}: class is undef! Optional 'class' key or key-as-class.")
$conf->{"class"} // ($key =~ /^[\w:]+$/a ? $key : undef)
MC/DC0%0/2
($conf->{"class"} // ($key =~ /^[\w:]+$/a ? $key : undef)) // die("Eon ${key}: class is undef! Optional 'class' key or key-as-class.")
$conf->{"class"}
($key =~ /^[\w:]+$/a ? $key : undef)
Truth table33%1/3
A // B
A= $conf->{"class"}B= ($key =~ /^[\w:]+$/a ? $key : undef)
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | // die "Eon $key: class is undef! Optional 'class' key or key-as-class."; | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 12 | ▶ | my $method = $conf->{method} // 'new'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$conf->{"method"} // "new"
MC/DC100%1/1
$conf->{"method"} // "new"
$conf->{"method"}
Truth table100%2/2
A
A= $conf->{"method"}
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | 12 | _require($pkg); | |||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 12 | ▶ | my $args = $conf->{arguments} // {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$conf->{"arguments"} // {}
MC/DC100%1/1
$conf->{"arguments"} // {}
$conf->{"arguments"}
Truth table100%2/2
A
A= $conf->{"arguments"}
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 12 | $args = $self->_resolve_args($args); | |||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 12 | my $eon = $self->_construct("$pkg#$method", $args); | |||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 12 | ▶ | for my $call (@{ $conf->{calls} // [] }) { | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$conf->{"calls"} // []
MC/DC100%1/1
$conf->{"calls"} // []
$conf->{"calls"}
Truth table100%2/2
A
A= $conf->{"calls"}
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 1 | my ($name, @call_args); | |||||||||||||||||||||||||||||||||||||||||
| 148 | 1 | ▶ | if(ref $call eq 'ARRAY') { ($name, @call_args) = @$call } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | else { $name = $call } | |||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | @call_args = map { $self->_resolve_value($_) } @call_args; | |||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | $eon->$name(@call_args); | |||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | $eon | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 12 | } | |||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | # Вызвать конструктор: именованные (hashref) или упорядоченные (arrayref) аргументы | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 12 | ▶ | sub _construct { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_construct: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 12 | my ($self, $action, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 160 | 12 | ▶ | my ($pkg, $method) = $action =~ /^([^#]+)#(.+)$/? ($1, $2): ($action, 'new'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 12 | _require($pkg); | |||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 12 | ▶ | ref($args) eq 'ARRAY'? $pkg->$method(@$args): $pkg->$method(%$args); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | # Подгрузить пакет, если он ещё не определён в памяти | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 24 | ▶ | sub _require { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_require: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | 24 | my ($pkg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 170 | 24 | ▶ | return if $pkg->can('new') || $pkg->can('does'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$pkg->can("new") or $pkg->can("does")
MC/DC50%1/2
$pkg->can("new") or $pkg->can("does")
$pkg->can("new")
$pkg->can("does")
Truth table66%2/3
A or B
A= $pkg->can("new")B= $pkg->can("does")
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 7 | $pkg =~ s!::!/!g; | |||||||||||||||||||||||||||||||||||||||||
| 172 | 7 | $pkg =~ s!\z!.pm!; | |||||||||||||||||||||||||||||||||||||||||
| 173 | 7 | require $pkg; | |||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | # Есть ли файл такого пакета на @INC (для ветки autoware в get) | ||||||||||||||||||||||||||||||||||||||||||
| 177 | 2 | ▶ | sub _find_pm { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_find_pm: called CC=6 SCAR=19.3
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 2 | my ($pkg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 179 | 2 | ▶ | return 1 if $pkg->can('new') || $pkg->can('does'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$pkg->can("new") or $pkg->can("does")
MC/DC0%0/2
$pkg->can("new") or $pkg->can("does")
$pkg->can("new")
$pkg->can("does")
Truth table33%1/3
A or B
A= $pkg->can("new")B= $pkg->can("does")
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 2 | my $path = $pkg =~ s!::!/!gr; | |||||||||||||||||||||||||||||||||||||||||
| 181 | 2 | $path .= '.pm'; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 2 | for my $dir (@INC) { | |||||||||||||||||||||||||||||||||||||||||
| 183 | 20 | ▶ | next if ref $dir; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 20 | ▶ | return 1 if -e "$dir/$path"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | '' | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 2 | } | |||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | # Строковое действие -> хеш-конфигурация {class, method} | ||||||||||||||||||||||||||||||||||||||||||
| 190 | 66 | ▶ | sub _hash_config { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_hash_config: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 66 | my ($action) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 192 | 66 | ▶ | return $action if ref $action eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 22 | ▶ | return undef unless defined $action && $action ne ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $action and $action ne ""
MC/DC50%1/2
defined $action and $action ne ""
defined $action
$action ne ""
Truth table66%2/3
A and B
A= defined $actionB= $action ne ""
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 16 | ▶ | my ($pkg, $method) = $action =~ /^([^#]+)#(.+)$/? ($1, $2): ($action, 'new'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | 16 | +{ class => $pkg, method => $method }; | |||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | # Хеш-конфигурация -> строковое действие 'класс#метод' | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 3 | ▶ | sub _string_config { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_string_config: called CC=3 SCAR=12.5
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 3 | my ($conf) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 201 | 3 | ▶ | return undef unless defined $conf && ref $conf eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $conf and ref $conf eq "HASH"
MC/DC0%0/2
defined $conf and ref $conf eq "HASH"
defined $conf
ref $conf eq "HASH"
Truth table33%1/3
A and B
A= defined $confB= ref $conf eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 3 | join '#', @$conf{qw/class method/}; | |||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | # Заменить в аргументах ссылки "@key" на эоны | ||||||||||||||||||||||||||||||||||||||||||
| 206 | 12 | ▶ | sub _resolve_args { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_resolve_args: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | 12 | my ($self, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 208 | 12 | ▶ | if(ref $args eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | 1 | +[ map { $self->_resolve_value($_) } @$args ] | |||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||
| 211 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 11 | +{ map { $_ => $self->_resolve_value($args->{$_}) } keys %$args } | |||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | # Значение, начинающееся с "@", воспринимается как ссылка на эон | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 8 | ▶ | sub _resolve_value { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_resolve_value: called CC=4 SCAR=14.6
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 8 | my ($self, $val) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 219 | 8 | ▶ | return $val unless defined $val && !ref $val && $val =~ /^@(.+)/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $val and not ref $val and $val =~ /^@(.+)/u
defined $val and not ref $val
MC/DC33%1/3
defined $val and not ref $val and $val =~ /^@(.+)/u
defined $val
not ref $val
$val =~ /^@(.+)/u
Truth table50%2/4
A and not(B) and C
A= defined $valB= not ref $valC= $val =~ /^@(.+)/u
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 2 | $self->resolve($1); | |||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | __END__ | ||||||||||||||||||||||||||||||||||||||||||