| 1 | package Catalyst::Seal::Modifiers; | ||||||||||||||||||||||||||||||||||||||||||
| 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 | 19 | ▶ | use Sub::Util 1.40 (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 19 | ▶ | use Catalyst::Seal (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 19 | ▶ | use Catalyst::Seal::Guard (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 19 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 19 | our @SKIP_CLASS = (qr/\A Catalyst::Log (?: :: | \z ) /x); | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 19 | my %FLAT; | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | sub flattened { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
flattened: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | _reap(); | |||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | return map { "$_->{class}::$_->{name}" } values %FLAT; | |||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 285 | ▶ | sub _installed { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_installed: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 285 | my ($class, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 19 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 285 | return *{"${class}::${name}"}{CODE}; | |||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 14 | ▶ | sub _reap { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_reap: called CC=4 SCAR=15.6
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 14 | for my $addr (keys %FLAT) { | |||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | my $rec = $FLAT{$addr}; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | my $installed = _installed($rec->{class}, $rec->{name}); | |||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | next if $installed && Scalar::Util::refaddr($installed) == Scalar::Util::refaddr($rec->{flat}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$installed and builtin::refaddr($installed) == builtin::refaddr($rec->{"flat"})
MC/DC0%0/2
$installed and builtin::refaddr($installed) == builtin::refaddr($rec->{"flat"})
$installed
builtin::refaddr($installed) == builtin::refaddr($rec->{"flat"})
Truth table33%1/3
A and B
A= $installedB= builtin::refaddr($installed) == builtin::refaddr($rec->{"flat"})
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | delete $FLAT{$addr}; | |||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 14 | return; | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 161 | ▶ | sub _skip_class { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_skip_class: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 161 | my ($class) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 161 | for my $re (@SKIP_CLASS) { | |||||||||||||||||||||||||||||||||||||||||
| 42 | 161 | ▶ | return 1 if $class =~ $re; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 160 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 12 | ▶ | sub _candidate_classes { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_candidate_classes: called CC=14 SCAR=27.6
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 12 | my ($app) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 12 | my @roots = ($app); | |||||||||||||||||||||||||||||||||||||||||
| 51 | 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
}
}
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 12 | ▶ | push @roots, map { ref $_ || $_ } values %$components; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
ref $_ || $_
MC/DC0%0/2
ref $_ || $_
ref $_
$_
Truth table66%2/3
A || B
A= ref $_B= $_
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 12 | for my $acc (qw(request_class response_class context_class | |||||||||||||||||||||||||||||||||||||||||
| 55 | dispatcher_class engine_class stats_class)) { | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 72 | ▶ | next unless $app->can($acc); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 72 | my $class = eval { $app->$acc }; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 72 | ▶ | push @roots, $class if defined $class && !ref $class; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $class and not ref $class
MC/DC50%1/2
defined $class and not ref $class
defined $class
not ref $class
Truth table66%2/3
A and not(B)
A= defined $classB= not ref $class
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 12 | my (%seen, @classes); | |||||||||||||||||||||||||||||||||||||||||
| 62 | 12 | for my $root (@roots) { | |||||||||||||||||||||||||||||||||||||||||
| 63 | 120 | ▶ | next unless defined $root && length $root; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $root and length $root
MC/DC0%0/2
defined $root and length $root
defined $root
length $root
Truth table33%1/3
A and B
A= defined $rootB= length $root
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 120 | ▶ | my $meta = Class::MOP::class_of($root) or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 120 | ▶ | next unless $meta->isa('Class::MOP::Class'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 120 | for my $class ($meta->linearized_isa) { | |||||||||||||||||||||||||||||||||||||||||
| 67 | 384 | ▶ | next if $seen{$class}++; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 156 | push @classes, $class; | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 12 | return @classes; | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 160 | ▶ | sub _wrapped_methods { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_wrapped_methods: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 160 | my ($meta) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 160 | my $map = eval { $meta->_method_map }; | |||||||||||||||||||||||||||||||||||||||||
| 78 | 160 | ▶ | unless (ref $map eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | Catalyst::Seal::note( | |||||||||||||||||||||||||||||||||||||||||
| 80 | "no method map on " . $meta->name . ", its modifiers were not flattened"); | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | return (); | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 160 | my @wrapped; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 160 | for my $name (sort keys %$map) { | |||||||||||||||||||||||||||||||||||||||||
| 86 | 4277 | my $method = $map->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 87 | 4277 | ▶ | next unless Scalar::Util::blessed($method) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
builtin::blessed($method) and $method->isa("Class::MOP::Method::Wrapped")
MC/DC100%2/2
builtin::blessed($method) and $method->isa("Class::MOP::Method::Wrapped")
builtin::blessed($method)
$method->isa("Class::MOP::Method::Wrapped")
Truth table100%3/3
A and B
A= builtin::blessed($method)B= $method->isa("Class::MOP::Method::Wrapped")
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | && $method->isa('Class::MOP::Method::Wrapped'); | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 283 | push @wrapped, [ $name, $method ]; | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 160 | return @wrapped; | |||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 354 | ▶ | sub _modifier_table { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_modifier_table: called CC=6 SCAR=19.1
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 354 | my ($method) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 354 | my $table = $method->{modifier_table}; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 354 | ▶ | return undef unless ref $table eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 354 | ▶ | return undef unless ref $table->{cache} eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 354 | ▶ | return undef unless ref $table->{before} eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 354 | ▶ | return undef unless ref $table->{after} eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 354 | ▶ | return undef unless ref $table->{around} eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 354 | return $table; | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 161 | ▶ | sub flatten_class { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
flatten_class: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 161 | my ($class) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 161 | ▶ | return 0 if _skip_class($class); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 160 | ▶ | my $meta = Class::MOP::class_of($class) or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 160 | ▶ | return 0 unless $meta->isa('Class::MOP::Class'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 160 | ▶ | my @wrapped = _wrapped_methods($meta) or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 88 | ▶ | unless ($meta->is_immutable) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | Catalyst::Seal::note( | |||||||||||||||||||||||||||||||||||||||||
| 116 | "$class is mutable, its " . scalar(@wrapped) . " wrapped method(s) were not flattened"); | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 87 | my $count = 0; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 87 | $count += _flatten_method($class, @$_) for @wrapped; | |||||||||||||||||||||||||||||||||||||||||
| 122 | 87 | return $count; | |||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 282 | ▶ | sub _flatten_method { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_flatten_method: called CC=6 SCAR=19.2
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 282 | my ($class, $name, $method) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 282 | ▶ | return 0 if $FLAT{ Scalar::Util::refaddr $method }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 282 | my $table = _modifier_table($method); | |||||||||||||||||||||||||||||||||||||||||
| 131 | 282 | ▶ | unless ($table) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | Catalyst::Seal::note( | |||||||||||||||||||||||||||||||||||||||||
| 133 | "${class}::${name} has a modifier table this release does not know, not flattened"); | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 282 | my $installed = _installed($class, $name); | |||||||||||||||||||||||||||||||||||||||||
| 138 | 282 | ▶ | unless ($installed && Scalar::Util::refaddr($installed) == Scalar::Util::refaddr($method->body)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$installed and builtin::refaddr($installed) == builtin::refaddr($method->body)
MC/DC0%0/2
$installed and builtin::refaddr($installed) == builtin::refaddr($method->body)
$installed
builtin::refaddr($installed) == builtin::refaddr($method->body)
Truth table33%1/3
A and B
A= $installedB= builtin::refaddr($installed) == builtin::refaddr($method->body)
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | Catalyst::Seal::note( | |||||||||||||||||||||||||||||||||||||||||
| 140 | "${class}::${name} is not the body the metaclass has, not flattened"); | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 282 | my $flat = $table->{cache}; | |||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | Sub::Util::set_subname( | ||||||||||||||||||||||||||||||||||||||||||
| 147 | $method->package_name . '::_wrapped_' . $method->name => $flat) | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 282 | ▶ | unless Scalar::Util::refaddr($flat) == Scalar::Util::refaddr($table->{orig}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | { | ||||||||||||||||||||||||||||||||||||||||||
| 151 | 19 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 19 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 282 | *{"${class}::${name}"} = $flat; | |||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 282 | $FLAT{ Scalar::Util::refaddr $method } = { | |||||||||||||||||||||||||||||||||||||||||
| 157 | class => $class, | ||||||||||||||||||||||||||||||||||||||||||
| 158 | name => $name, | ||||||||||||||||||||||||||||||||||||||||||
| 159 | flat => $flat, | ||||||||||||||||||||||||||||||||||||||||||
| 160 | method => $method, | ||||||||||||||||||||||||||||||||||||||||||
| 161 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 282 | _install_unflatten_hook(); | |||||||||||||||||||||||||||||||||||||||||
| 163 | 282 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 10 | ▶ | sub unflatten_method { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unflatten_method: called CC=5 SCAR=16.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 10 | my ($method) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 10 | ▶ | return 0 unless Scalar::Util::blessed($method); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 9 | ▶ | my $rec = $FLAT{ Scalar::Util::refaddr $method } or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 2 | my ($class, $name) = ($rec->{class}, $rec->{name}); | |||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | 2 | my $installed = _installed($rec->{class}, $rec->{name}); | |||||||||||||||||||||||||||||||||||||||||
| 174 | 2 | ▶ | if ($installed && Scalar::Util::refaddr($installed) == Scalar::Util::refaddr($rec->{flat})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$installed and builtin::refaddr($installed) == builtin::refaddr($rec->{"flat"})
MC/DC0%0/2
$installed and builtin::refaddr($installed) == builtin::refaddr($rec->{"flat"})
$installed
builtin::refaddr($installed) == builtin::refaddr($rec->{"flat"})
Truth table33%1/3
A and B
A= $installedB= builtin::refaddr($installed) == builtin::refaddr($rec->{"flat"})
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 19 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 19 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | 2 | *{"${class}::${name}"} = $method->body; | |||||||||||||||||||||||||||||||||||||||||
| 178 | 2 | Catalyst::Seal::note("${class}::${name} un-flattened, a modifier was added after seal"); | |||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | Catalyst::Seal::note( | |||||||||||||||||||||||||||||||||||||||||
| 182 | "${class}::${name} was replaced after it was flattened, left alone"); | ||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | 2 | delete $FLAT{ Scalar::Util::refaddr $method }; | |||||||||||||||||||||||||||||||||||||||||
| 186 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | 19 | my $HOOKED = 0; | |||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | 282 | ▶ | sub _install_unflatten_hook { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_install_unflatten_hook: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 282 | ▶ | return if $HOOKED++; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 14 | for my $kind (qw(before after around)) { | |||||||||||||||||||||||||||||||||||||||||
| 194 | 42 | my $sym = "Class::MOP::Method::Wrapped::add_${kind}_modifier"; | |||||||||||||||||||||||||||||||||||||||||
| 195 | 19 | ▶ | my $orig = do { no strict 'refs'; \&{$sym} }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 19 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 19 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 42 | ▶ | *{$sym} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 8 | unflatten_method($_[0]); | |||||||||||||||||||||||||||||||||||||||||
| 200 | 8 | ▶ | if (Scalar::Util::blessed($_[0]) && $_[0]->can('name') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
builtin::blessed($_[0]) and $_[0]->can("name") and $_[0]->name eq "BUILD"
builtin::blessed($_[0]) and $_[0]->can("name")
MC/DC33%1/3
builtin::blessed($_[0]) and $_[0]->can("name") and $_[0]->name eq "BUILD"
builtin::blessed($_[0])
$_[0]->can("name")
$_[0]->name eq "BUILD"
Truth table50%2/4
A and B and C
A= builtin::blessed($_[0])B= $_[0]->can("name")C= $_[0]->name eq "BUILD"
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | && $_[0]->name eq 'BUILD') { | ||||||||||||||||||||||||||||||||||||||||||
| 202 | 2 | require Catalyst::Seal::Construct; | |||||||||||||||||||||||||||||||||||||||||
| 203 | 2 | Catalyst::Seal::Construct::_unseal_constructors(); | |||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | 8 | goto &$orig; | |||||||||||||||||||||||||||||||||||||||||
| 206 | 42 | }; | |||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 14 | return; | |||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | 19 | my @GUARDED_SETTERS = qw(status headers content_encoding content_length content_type); | |||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 19 | my %GUARD_DONE; | |||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 24 | ▶ | sub _short_circuit_guard { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_short_circuit_guard: called CC=10 SCAR=26.7
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | 24 | my ($key, $names, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | 24 | ▶ | return 0 if $GUARD_DONE{$key}++; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | 24 | ▶ | my $meta = Class::MOP::class_of('Catalyst::Response') or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | 24 | my (@lists, %count); | |||||||||||||||||||||||||||||||||||||||||
| 223 | 24 | for my $name (@$names) { | |||||||||||||||||||||||||||||||||||||||||
| 224 | 72 | my $method = eval { $meta->get_method($name) }; | |||||||||||||||||||||||||||||||||||||||||
| 225 | 72 | ▶ | unless (Scalar::Util::blessed($method) && $method->isa('Class::MOP::Method::Wrapped')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($method) and $method->isa("Class::MOP::Method::Wrapped")
MC/DC0%0/2
builtin::blessed($method) and $method->isa("Class::MOP::Method::Wrapped")
builtin::blessed($method)
$method->isa("Class::MOP::Method::Wrapped")
Truth table33%1/3
A and B
A= builtin::blessed($method)B= $method->isa("Class::MOP::Method::Wrapped")
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | Catalyst::Seal::note("Catalyst::Response::$name is not wrapped, guard not patched"); | |||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||
| 229 | 72 | ▶ | my $table = _modifier_table($method) or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | Catalyst::Seal::note("Catalyst::Response::$name has an unknown modifier table, guard not patched"); | |||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 232 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 72 | my $before = $table->{before}; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 72 | ▶ | unless (@$before == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | Catalyst::Seal::note(sprintf | |||||||||||||||||||||||||||||||||||||||||
| 236 | "Catalyst::Response::%s has %d before modifiers, not the one this patch was written against", | ||||||||||||||||||||||||||||||||||||||||||
| 237 | $name, scalar @$before); | ||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 72 | push @lists, $before; | |||||||||||||||||||||||||||||||||||||||||
| 241 | 72 | $count{ Scalar::Util::refaddr $before->[0] }++; | |||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | 24 | ▶ | unless (keys(%count) == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | Catalyst::Seal::note( | |||||||||||||||||||||||||||||||||||||||||
| 246 | "the Catalyst::Response guard is not one modifier shared by @$names, not patched"); | ||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | 24 | my $stock = $lists[0][0]; | |||||||||||||||||||||||||||||||||||||||||
| 251 | 24 | ▶ | my $fast = sub { return unless @_ > $args; goto &$stock }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | 24 | $_->[0] = $fast for @lists; | |||||||||||||||||||||||||||||||||||||||||
| 253 | 24 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | 12 | ▶ | Catalyst::Seal::register_step('response-guard' => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | 12 | require Class::MOP; | |||||||||||||||||||||||||||||||||||||||||
| 258 | 12 | require Catalyst::Response; | |||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | 12 | _short_circuit_guard('Catalyst::Response::setter_guard', | |||||||||||||||||||||||||||||||||||||||||
| 261 | \@GUARDED_SETTERS, 1); | ||||||||||||||||||||||||||||||||||||||||||
| 262 | 12 | _short_circuit_guard('Catalyst::Response::header_guard', | |||||||||||||||||||||||||||||||||||||||||
| 263 | ['header'], 2); | ||||||||||||||||||||||||||||||||||||||||||
| 264 | 12 | return; | |||||||||||||||||||||||||||||||||||||||||
| 265 | 19 | }); | |||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | 12 | ▶ | Catalyst::Seal::register_step('modifiers' => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | 12 | my ($app) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 269 | 12 | require Class::MOP; | |||||||||||||||||||||||||||||||||||||||||
| 270 | 12 | require Class::MOP::Method::Wrapped; | |||||||||||||||||||||||||||||||||||||||||
| 271 | 12 | _reap(); | |||||||||||||||||||||||||||||||||||||||||
| 272 | 12 | my $count = 0; | |||||||||||||||||||||||||||||||||||||||||
| 273 | 12 | $count += flatten_class($_) for _candidate_classes($app); | |||||||||||||||||||||||||||||||||||||||||
| 274 | 12 | ▶ | Catalyst::Seal::note("flattened $count wrapped method(s)") if $Catalyst::Seal::DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | 12 | return; | |||||||||||||||||||||||||||||||||||||||||
| 276 | 19 | }); | |||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | 19 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | __END__ | ||||||||||||||||||||||||||||||||||||||||||