| 1 | package Catalyst::Seal::ClassData; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 19 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 19 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 19 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 19 | ▶ | use Catalyst::Seal (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 19 | ▶ | use Catalyst::Seal::Guard (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 19 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 54 | ▶ | sub _classdata_accessors { | ||||||||||||||||||||||||||
|
Subroutine
_classdata_accessors: called CC=13 SCAR=26.5
| |||||||||||||||||||||||||||||
| 14 | 54 | my ($class) = @_; | |||||||||||||||||||||||||||
| 15 | 54 | ▶ | my $meta = Class::MOP::class_of($class) or return (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 54 | my %found; | |||||||||||||||||||||||||||
| 18 | 54 | for my $pkg ($meta->linearized_isa) { | |||||||||||||||||||||||||||
| 19 | 218 | ▶ | my $pkg_meta = Class::MOP::class_of($pkg) or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 218 | my %by_body; | |||||||||||||||||||||||||||
| 22 | 218 | for my $name ($pkg_meta->get_method_list) { | |||||||||||||||||||||||||||
| 23 | 7698 | ▶ | my $method = $pkg_meta->get_method($name) or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | 7698 | ▶ | my $body = eval { $method->body } or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 7698 | push @{ $by_body{ 0 + $body } }, [$name, $body]; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 218 | for my $pair (values %by_body) { | |||||||||||||||||||||||||||
| 29 | 7074 | ▶ | next unless @$pair == 2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 624 | my ($plain) = grep { $_->[0] !~ /\A_.+_accessor\z/ } @$pair; | |||||||||||||||||||||||||||
| 31 | 624 | my ($alias) = grep { $_->[0] =~ /\A_.+_accessor\z/ } @$pair; | |||||||||||||||||||||||||||
| 32 | 624 | ▶ | next unless $plain && $alias; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$plain and $alias
MC/DC50%1/2
$plain and $alias
$plain
$alias
Truth table66%2/3
A and B
A= $plainB= $alias
| |||||||||||||||||||||||||||||
| 33 | 612 | ▶ | next unless $alias->[0] eq "_$plain->[0]_accessor"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 612 | ▶ | $found{ $plain->[0] } ||= $plain->[1]; | ||||||||||||||||||||||||||
|
Condition33%1/3
$found{$plain->[0]} ||= $plain->[1]
MC/DC0%0/2
$found{$plain->[0]} ||= $plain->[1]
$found{$plain->[0]}
$plain->[1]
Truth table33%1/3
A ||= B
A= $found{$plain->[0]}B= $plain->[1]
| |||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | 54 | return %found; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 12 | ▶ | sub _classes_for { | ||||||||||||||||||||||||||
|
Subroutine
_classes_for: called CC=4 SCAR=14.3
| |||||||||||||||||||||||||||||
| 41 | 12 | my ($app) = @_; | |||||||||||||||||||||||||||
| 42 | 12 | my @classes = ($app); | |||||||||||||||||||||||||||
| 43 | 12 | ▶ | my $components = eval { $app->components } || {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
eval {
do {
$app->components
}
} || {}
MC/DC0%0/1
eval {
do {
$app->components
}
} || {}
eval {
do {
$app->components
}
}
Truth table50%1/2
A
A= eval {
do {
$app->components
}
}
| |||||||||||||||||||||||||||||
| 44 | 12 | ▶ | push @classes, map { ref $_ || $_ } values %$components; | ||||||||||||||||||||||||||
|
Condition66%2/3
ref $_ || $_
MC/DC0%0/2
ref $_ || $_
ref $_
$_
Truth table66%2/3
A || B
A= ref $_B= $_
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 12 | my %seen; | |||||||||||||||||||||||||||
| 47 | 12 | ▶ | return grep { !$seen{$_}++ } grep { defined && length } @classes; | ||||||||||||||||||||||||||
|
Condition33%1/3
defined $_ && length $_
MC/DC0%0/2
defined $_ && length $_
defined $_
length $_
Truth table33%1/3
A && B
A= defined $_B= length $_
| |||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 53 | ▶ | sub _seal_class { | ||||||||||||||||||||||||||
|
Subroutine
_seal_class: called CC=4 SCAR=14.5
| |||||||||||||||||||||||||||||
| 51 | 53 | my ($class) = @_; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 53 | my %accessors = _classdata_accessors($class); | |||||||||||||||||||||||||||
| 54 | 53 | my $sealed = 0; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 53 | for my $name (sort keys %accessors) { | |||||||||||||||||||||||||||
| 57 | 602 | my $value = eval { $class->$name }; | |||||||||||||||||||||||||||
| 58 | 602 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 0 | Catalyst::Seal::note("$class\::$name croaked while resolving, not sealed: $@"); | |||||||||||||||||||||||||||
| 60 | 0 | next; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 602 | my $ok = eval { | |||||||||||||||||||||||||||
| 64 | 19 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 65 | 602 | Catalyst::Seal::_install_const($class, $name, $value, $accessors{$name}); | |||||||||||||||||||||||||||
| 66 | 602 | 1; | |||||||||||||||||||||||||||
| 67 | }; | ||||||||||||||||||||||||||||
| 68 | 602 | ▶ | unless ($ok) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 0 | Catalyst::Seal::note("could not seal $class\::$name: $@"); | |||||||||||||||||||||||||||
| 70 | 0 | next; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | 602 | $sealed++; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 53 | return $sealed; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 1 | ▶ | sub _component_config { | ||||||||||||||||||||||||||
|
Subroutine
_component_config: called CC=6 SCAR=22.0
| |||||||||||||||||||||||||||||
| 79 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 80 | 1 | ▶ | my $config = $self->_config || {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->_config || {}
MC/DC0%0/1
$self->_config || {}
$self->_config
Truth table50%1/2
A
A= $self->_config
| |||||||||||||||||||||||||||||
| 81 | 1 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | my $newconfig = { %{@_ > 1 ? {@_} : $_[0]} }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 0 | $self->_config( | |||||||||||||||||||||||||||
| 84 | $self->merge_config_hashes( $config, $newconfig ) | ||||||||||||||||||||||||||||
| 85 | ); | ||||||||||||||||||||||||||||
| 86 | } else { | ||||||||||||||||||||||||||||
| 87 | 1 | ▶ | my $class = Scalar::Util::blessed($self) || $self; | ||||||||||||||||||||||||||
|
Condition33%1/3
builtin::blessed($self) || $self
MC/DC0%0/2
builtin::blessed($self) || $self
builtin::blessed($self)
$self
Truth table33%1/3
A || B
A= builtin::blessed($self)B= $self
| |||||||||||||||||||||||||||||
| 88 | 19 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 89 | 1 | ▶ | unless ( ${"${class}::_config"} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | $self->_config( Catalyst::Utils::merge_hashes($config, {}) ); | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | 1 | return $self->_config; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 19 | my $CONFIG_PATCHED = 0; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 12 | ▶ | Catalyst::Seal::register_step('classdata' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=19.0
| |||||||||||||||||||||||||||||
| 99 | 12 | my ($app) = @_; | |||||||||||||||||||||||||||
| 100 | 12 | require Class::MOP; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 12 | ▶ | eval { $app->context_class( ref $app || $app ) unless $app->context_class }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $app || $app
MC/DC0%0/2
ref $app || $app
ref $app
$app
Truth table33%1/3
A || B
A= ref $appB= $app
| |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 12 | my $sealed = 0; | |||||||||||||||||||||||||||
| 105 | 12 | $sealed += _seal_class($_) for _classes_for($app); | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 12 | ▶ | unless ($CONFIG_PATCHED++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 12 | Catalyst::Seal::Guard::replace( | |||||||||||||||||||||||||||
| 109 | 'Catalyst::Component::config' => \&_component_config); | ||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 12 | ▶ | Catalyst::Seal::note("sealed $sealed class data accessor(s)") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | if $Catalyst::Seal::DEBUG; | ||||||||||||||||||||||||||||
| 114 | 12 | return; | |||||||||||||||||||||||||||
| 115 | 19 | }); | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 19 | 1; | |||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | __END__ | ||||||||||||||||||||||||||||