| 1 | package Devel::Declare::Context::Simple; | ||||||||||||
| 2 | |||||||||||||
| 3 | 6 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 6 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 6 | ▶ | use Devel::Declare (); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 6 | ▶ | use B::Hooks::EndOfScope; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 6 | ▶ | use Carp qw/confess/; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 6 | our $VERSION = '0.006022'; | |||||||||||
| 10 | 6 | $VERSION =~ tr/_//d; | |||||||||||
| 11 | |||||||||||||
| 12 | 23 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 13 | 23 | my $class = shift; | |||||||||||
| 14 | 23 | bless {@_}, $class; | |||||||||||
| 15 | } | ||||||||||||
| 16 | |||||||||||||
| 17 | 36 | ▶ | sub init { | ||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 18 | 36 | my $self = shift; | |||||||||||
| 19 | 36 | @{$self}{ qw(Declarator Offset WarningOnRedefined) } = @_; | |||||||||||
| 20 | 36 | return $self; | |||||||||||
| 21 | } | ||||||||||||
| 22 | |||||||||||||
| 23 | 606 | ▶ | sub offset { | ||||||||||
|
Subroutine
offset: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 24 | 606 | my $self = shift; | |||||||||||
| 25 | return $self->{Offset} | ||||||||||||
| 26 | 606 | } | |||||||||||
| 27 | |||||||||||||
| 28 | 213 | ▶ | sub inc_offset { | ||||||||||
|
Subroutine
inc_offset: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 29 | 213 | my $self = shift; | |||||||||||
| 30 | 213 | $self->{Offset} += shift; | |||||||||||
| 31 | } | ||||||||||||
| 32 | |||||||||||||
| 33 | 76 | ▶ | sub declarator { | ||||||||||
|
Subroutine
declarator: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 34 | 76 | my $self = shift; | |||||||||||
| 35 | return $self->{Declarator} | ||||||||||||
| 36 | 76 | } | |||||||||||
| 37 | |||||||||||||
| 38 | 11 | ▶ | sub warning_on_redefine { | ||||||||||
|
Subroutine
warning_on_redefine: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 39 | 11 | my $self = shift; | |||||||||||
| 40 | return $self->{WarningOnRedefined} | ||||||||||||
| 41 | 11 | } | |||||||||||
| 42 | |||||||||||||
| 43 | 36 | ▶ | sub skip_declarator { | ||||||||||
|
Subroutine
skip_declarator: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||
| 44 | 36 | my $self = shift; | |||||||||||
| 45 | 36 | my $decl = $self->declarator; | |||||||||||
| 46 | 36 | my $len = Devel::Declare::toke_scan_word($self->offset, 0); | |||||||||||
| 47 | 36 | ▶ | confess "Couldn't find declarator '$decl'" | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 48 | unless $len; | ||||||||||||
| 49 | |||||||||||||
| 50 | 36 | my $linestr = $self->get_linestr; | |||||||||||
| 51 | 36 | my $name = substr($linestr, $self->offset, $len); | |||||||||||
| 52 | 36 | ▶ | confess "Expected declarator '$decl', got '${name}'" | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 53 | unless $name eq $decl; | ||||||||||||
| 54 | |||||||||||||
| 55 | 36 | $self->inc_offset($len); | |||||||||||
| 56 | } | ||||||||||||
| 57 | |||||||||||||
| 58 | 177 | ▶ | sub skipspace { | ||||||||||
|
Subroutine
skipspace: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 59 | 177 | my $self = shift; | |||||||||||
| 60 | 177 | $self->inc_offset(Devel::Declare::toke_skipspace($self->offset)); | |||||||||||
| 61 | } | ||||||||||||
| 62 | |||||||||||||
| 63 | 179 | ▶ | sub get_linestr { | ||||||||||
|
Subroutine
get_linestr: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 64 | 179 | my $self = shift; | |||||||||||
| 65 | 179 | my $line = Devel::Declare::get_linestr(); | |||||||||||
| 66 | 179 | return $line; | |||||||||||
| 67 | } | ||||||||||||
| 68 | |||||||||||||
| 69 | 97 | ▶ | sub set_linestr { | ||||||||||
|
Subroutine
set_linestr: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 70 | 97 | my $self = shift; | |||||||||||
| 71 | 97 | my ($line) = @_; | |||||||||||
| 72 | 97 | Devel::Declare::set_linestr($line); | |||||||||||
| 73 | } | ||||||||||||
| 74 | |||||||||||||
| 75 | 54 | ▶ | sub strip_name { | ||||||||||
|
Subroutine
strip_name: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 76 | 54 | my $self = shift; | |||||||||||
| 77 | 54 | $self->skipspace; | |||||||||||
| 78 | 54 | ▶ | if (my $len = Devel::Declare::toke_scan_word( $self->offset, 1 )) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 79 | 34 | my $linestr = $self->get_linestr(); | |||||||||||
| 80 | 34 | my $name = substr( $linestr, $self->offset, $len ); | |||||||||||
| 81 | 34 | substr( $linestr, $self->offset, $len ) = ''; | |||||||||||
| 82 | 34 | $self->set_linestr($linestr); | |||||||||||
| 83 | 34 | return $name; | |||||||||||
| 84 | } | ||||||||||||
| 85 | |||||||||||||
| 86 | 20 | $self->skipspace; | |||||||||||
| 87 | 20 | return; | |||||||||||
| 88 | } | ||||||||||||
| 89 | |||||||||||||
| 90 | 0 | ▶ | sub strip_ident { | ||||||||||
|
Subroutine
strip_ident: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 91 | 0 | my $self = shift; | |||||||||||
| 92 | 0 | $self->skipspace; | |||||||||||
| 93 | 0 | ▶ | if (my $len = Devel::Declare::toke_scan_ident( $self->offset )) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 94 | 0 | my $linestr = $self->get_linestr(); | |||||||||||
| 95 | 0 | my $ident = substr( $linestr, $self->offset, $len ); | |||||||||||
| 96 | 0 | substr( $linestr, $self->offset, $len ) = ''; | |||||||||||
| 97 | 0 | $self->set_linestr($linestr); | |||||||||||
| 98 | 0 | return $ident; | |||||||||||
| 99 | } | ||||||||||||
| 100 | |||||||||||||
| 101 | 0 | $self->skipspace; | |||||||||||
| 102 | 0 | return; | |||||||||||
| 103 | } | ||||||||||||
| 104 | |||||||||||||
| 105 | 38 | ▶ | sub strip_proto { | ||||||||||
|
Subroutine
strip_proto: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||
| 106 | 38 | my $self = shift; | |||||||||||
| 107 | 38 | $self->skipspace; | |||||||||||
| 108 | |||||||||||||
| 109 | 38 | my $linestr = $self->get_linestr(); | |||||||||||
| 110 | 38 | ▶ | if (substr($linestr, $self->offset, 1) eq '(') { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 111 | 26 | my $length = Devel::Declare::toke_scan_str($self->offset); | |||||||||||
| 112 | 26 | my $proto = Devel::Declare::get_lex_stuff(); | |||||||||||
| 113 | 26 | Devel::Declare::clear_lex_stuff(); | |||||||||||
| 114 | 26 | $linestr = $self->get_linestr(); | |||||||||||
| 115 | |||||||||||||
| 116 | 26 | ▶ | substr($linestr, $self->offset, | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 117 | defined($length) ? $length : length($linestr)) = ''; | ||||||||||||
| 118 | 26 | $self->set_linestr($linestr); | |||||||||||
| 119 | |||||||||||||
| 120 | 26 | return $proto; | |||||||||||
| 121 | } | ||||||||||||
| 122 | 12 | return; | |||||||||||
| 123 | } | ||||||||||||
| 124 | |||||||||||||
| 125 | 2 | ▶ | sub strip_names_and_args { | ||||||||||
|
Subroutine
strip_names_and_args: called CC=8 SCAR=20.9
Pod
undocumented
| |||||||||||||
| 126 | 2 | my $self = shift; | |||||||||||
| 127 | 2 | $self->skipspace; | |||||||||||
| 128 | |||||||||||||
| 129 | 2 | my @args; | |||||||||||
| 130 | |||||||||||||
| 131 | 2 | my $linestr = $self->get_linestr; | |||||||||||
| 132 | 2 | ▶ | if (substr($linestr, $self->offset, 1) eq '(') { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 133 | # We had a leading paren, so we will now expect comma separated | ||||||||||||
| 134 | # arguments | ||||||||||||
| 135 | 1 | substr($linestr, $self->offset, 1) = ''; | |||||||||||
| 136 | 1 | $self->set_linestr($linestr); | |||||||||||
| 137 | 1 | $self->skipspace; | |||||||||||
| 138 | |||||||||||||
| 139 | # At this point we expect to have a comma-separated list of | ||||||||||||
| 140 | # barewords with optional protos afterward, so loop until we | ||||||||||||
| 141 | # run out of comma-separated values | ||||||||||||
| 142 | 1 | while (1) { | |||||||||||
| 143 | # Get the bareword | ||||||||||||
| 144 | 3 | my $thing = $self->strip_name; | |||||||||||
| 145 | # If there's no bareword here, bail | ||||||||||||
| 146 | 3 | ▶ | confess "failed to parse bareword. found ${linestr}" | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 147 | unless defined $thing; | ||||||||||||
| 148 | |||||||||||||
| 149 | 3 | $linestr = $self->get_linestr; | |||||||||||
| 150 | 3 | ▶ | if (substr($linestr, $self->offset, 1) eq '(') { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 151 | # This one had a proto, pull it out | ||||||||||||
| 152 | 2 | push(@args, [ $thing, $self->strip_proto ]); | |||||||||||
| 153 | } else { | ||||||||||||
| 154 | # This had no proto, so store it with an undef | ||||||||||||
| 155 | 1 | push(@args, [ $thing, undef ]); | |||||||||||
| 156 | } | ||||||||||||
| 157 | 3 | $self->skipspace; | |||||||||||
| 158 | 3 | $linestr = $self->get_linestr; | |||||||||||
| 159 | |||||||||||||
| 160 | 3 | ▶ | if (substr($linestr, $self->offset, 1) eq ',') { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 161 | # We found a comma, strip it out and set things up for | ||||||||||||
| 162 | # another iteration | ||||||||||||
| 163 | 2 | substr($linestr, $self->offset, 1) = ''; | |||||||||||
| 164 | 2 | $self->set_linestr($linestr); | |||||||||||
| 165 | 2 | $self->skipspace; | |||||||||||
| 166 | } else { | ||||||||||||
| 167 | # No comma, get outta here | ||||||||||||
| 168 | 1 | last; | |||||||||||
| 169 | } | ||||||||||||
| 170 | } | ||||||||||||
| 171 | |||||||||||||
| 172 | # look for the final closing paren of the list | ||||||||||||
| 173 | 1 | ▶ | if (substr($linestr, $self->offset, 1) eq ')') { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 174 | 1 | substr($linestr, $self->offset, 1) = ''; | |||||||||||
| 175 | 1 | $self->set_linestr($linestr); | |||||||||||
| 176 | 1 | $self->skipspace; | |||||||||||
| 177 | } | ||||||||||||
| 178 | else { | ||||||||||||
| 179 | # fail if it isn't there | ||||||||||||
| 180 | 0 | confess "couldn't find closing paren for argument. found ${linestr}" | |||||||||||
| 181 | } | ||||||||||||
| 182 | } else { | ||||||||||||
| 183 | # No parens, so expect a single arg | ||||||||||||
| 184 | 1 | my $thing = $self->strip_name; | |||||||||||
| 185 | # If there's no bareword here, bail | ||||||||||||
| 186 | 1 | ▶ | confess "failed to parse bareword. found ${linestr}" | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 187 | unless defined $thing; | ||||||||||||
| 188 | 1 | $linestr = $self->get_linestr; | |||||||||||
| 189 | 1 | ▶ | if (substr($linestr, $self->offset, 1) eq '(') { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 190 | # This one had a proto, pull it out | ||||||||||||
| 191 | 0 | push(@args, [ $thing, $self->strip_proto ]); | |||||||||||
| 192 | } else { | ||||||||||||
| 193 | # This had no proto, so store it with an undef | ||||||||||||
| 194 | 1 | push(@args, [ $thing, undef ]); | |||||||||||
| 195 | } | ||||||||||||
| 196 | } | ||||||||||||
| 197 | |||||||||||||
| 198 | 2 | return \@args; | |||||||||||
| 199 | } | ||||||||||||
| 200 | |||||||||||||
| 201 | 18 | ▶ | sub strip_attrs { | ||||||||||
|
Subroutine
strip_attrs: called CC=6 SCAR=18.5
Pod
undocumented
| |||||||||||||
| 202 | 18 | my $self = shift; | |||||||||||
| 203 | 18 | $self->skipspace; | |||||||||||
| 204 | |||||||||||||
| 205 | 18 | my $linestr = Devel::Declare::get_linestr; | |||||||||||
| 206 | 18 | my $attrs = ''; | |||||||||||
| 207 | |||||||||||||
| 208 | 18 | ▶ | if (substr($linestr, $self->offset, 1) eq ':') { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 209 | 1 | ▶ | while (substr($linestr, $self->offset, 1) ne '{') { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 210 | 2 | ▶ | if (substr($linestr, $self->offset, 1) eq ':') { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 211 | 1 | substr($linestr, $self->offset, 1) = ''; | |||||||||||
| 212 | 1 | Devel::Declare::set_linestr($linestr); | |||||||||||
| 213 | |||||||||||||
| 214 | 1 | $attrs .= ':'; | |||||||||||
| 215 | } | ||||||||||||
| 216 | |||||||||||||
| 217 | 2 | $self->skipspace; | |||||||||||
| 218 | 2 | $linestr = Devel::Declare::get_linestr(); | |||||||||||
| 219 | |||||||||||||
| 220 | 2 | ▶ | if (my $len = Devel::Declare::toke_scan_word($self->offset, 0)) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 221 | 1 | my $name = substr($linestr, $self->offset, $len); | |||||||||||
| 222 | 1 | substr($linestr, $self->offset, $len) = ''; | |||||||||||
| 223 | 1 | Devel::Declare::set_linestr($linestr); | |||||||||||
| 224 | |||||||||||||
| 225 | 1 | $attrs .= " ${name}"; | |||||||||||
| 226 | |||||||||||||
| 227 | 1 | ▶ | if (substr($linestr, $self->offset, 1) eq '(') { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 228 | 0 | my $length = Devel::Declare::toke_scan_str($self->offset); | |||||||||||
| 229 | 0 | my $arg = Devel::Declare::get_lex_stuff(); | |||||||||||
| 230 | 0 | Devel::Declare::clear_lex_stuff(); | |||||||||||
| 231 | 0 | $linestr = Devel::Declare::get_linestr(); | |||||||||||
| 232 | 0 | substr($linestr, $self->offset, $length) = ''; | |||||||||||
| 233 | 0 | Devel::Declare::set_linestr($linestr); | |||||||||||
| 234 | |||||||||||||
| 235 | 0 | $attrs .= "(${arg})"; | |||||||||||
| 236 | } | ||||||||||||
| 237 | } | ||||||||||||
| 238 | } | ||||||||||||
| 239 | |||||||||||||
| 240 | 1 | $linestr = Devel::Declare::get_linestr(); | |||||||||||
| 241 | } | ||||||||||||
| 242 | |||||||||||||
| 243 | 18 | return $attrs; | |||||||||||
| 244 | } | ||||||||||||
| 245 | |||||||||||||
| 246 | |||||||||||||
| 247 | 54 | ▶ | sub get_curstash_name { | ||||||||||
|
Subroutine
get_curstash_name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 248 | 54 | return Devel::Declare::get_curstash_name; | |||||||||||
| 249 | } | ||||||||||||
| 250 | |||||||||||||
| 251 | 36 | ▶ | sub shadow { | ||||||||||
|
Subroutine
shadow: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 252 | 36 | my $self = shift; | |||||||||||
| 253 | 36 | my $pack = $self->get_curstash_name; | |||||||||||
| 254 | 36 | Devel::Declare::shadow_sub( $pack . '::' . $self->declarator, $_[0] ); | |||||||||||
| 255 | } | ||||||||||||
| 256 | |||||||||||||
| 257 | 36 | ▶ | sub inject_if_block { | ||||||||||
|
Subroutine
inject_if_block: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||
| 258 | 36 | my $self = shift; | |||||||||||
| 259 | 36 | my $inject = shift; | |||||||||||
| 260 | 36 | ▶ | my $before = shift || ''; | ||||||||||
|
Condition100%2/2
shift() || ''
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||
| 261 | |||||||||||||
| 262 | 36 | $self->skipspace; | |||||||||||
| 263 | |||||||||||||
| 264 | 36 | my $linestr = $self->get_linestr; | |||||||||||
| 265 | 36 | ▶ | if (substr($linestr, $self->offset, 1) eq '{') { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 266 | 33 | substr($linestr, $self->offset + 1, 0) = $inject; | |||||||||||
| 267 | 33 | substr($linestr, $self->offset, 0) = $before; | |||||||||||
| 268 | 33 | $self->set_linestr($linestr); | |||||||||||
| 269 | 33 | return 1; | |||||||||||
| 270 | } | ||||||||||||
| 271 | 3 | return 0; | |||||||||||
| 272 | } | ||||||||||||
| 273 | |||||||||||||
| 274 | 24 | ▶ | sub scope_injector_call { | ||||||||||
|
Subroutine
scope_injector_call: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||
| 275 | 24 | my $self = shift; | |||||||||||
| 276 | 24 | ▶ | my $inject = shift || ''; | ||||||||||
|
Condition50%1/2
shift() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 277 | 24 | return ' BEGIN { ' . ref($self) . "->inject_scope('${inject}') }; "; | |||||||||||
| 278 | } | ||||||||||||
| 279 | |||||||||||||
| 280 | 21 | ▶ | sub inject_scope { | ||||||||||
|
Subroutine
inject_scope: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 281 | 21 | my $class = shift; | |||||||||||
| 282 | 21 | my $inject = shift; | |||||||||||
| 283 | 21 | ▶ | on_scope_end { | ||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||
| 284 | 21 | my $linestr = Devel::Declare::get_linestr; | |||||||||||
| 285 | 21 | ▶ | return unless defined $linestr; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 286 | 21 | my $offset = Devel::Declare::get_linestr_offset; | |||||||||||
| 287 | 21 | substr( $linestr, $offset, 0 ) = ';' . $inject; | |||||||||||
| 288 | 21 | Devel::Declare::set_linestr($linestr); | |||||||||||
| 289 | 21 | }; | |||||||||||
| 290 | } | ||||||||||||
| 291 | |||||||||||||
| 292 | 6 | 1; | |||||||||||
| 293 | # vi:sw=2 ts=2 | ||||||||||||