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