/usr/share/perl5/Inline/denter.pm is in libinline-perl 0.53-1.
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 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 | package Inline::denter;
use strict;
use Carp;
use AutoLoader 'AUTOLOAD';
sub new {
my $class = shift;
bless {width => 4,
comma => " : ",
level => 0,
tabwidth => 8,
}, $class;
}
# Prevent a taint exception being thrown by AutoLoader.pm.
# Serves no other purpose.
sub DESTROY {
}
sub undent {
local $/ = "\n";
my ($o, $text) = @_;
my ($comma) = $o->{comma};
my $package = caller;
$package = caller(1) if $package eq 'Inline::denter';
%{$o->{xref}} = ();
@{$o->{objects}} = ();
@{$o->{context}} = ();
my $glob = '';
chomp $text;
@{$o->{lines}} = split $/, $text;
$o->{level} = 0;
$o->{line} ||= 1;
$o->_setup_line;
while (not $o->{done}) {
if ($o->{level} == 0 and
$o->{content} =~ /^(\w+)\s*$comma\s*(.*)$/) {
$o->{content} = $2;
no strict 'refs';
push @{$o->{objects}}, "$1";
}
push @{$o->{objects}}, $o->_undent_data;
}
return @{$o->{objects}};
}
sub _undent_data {
my $o = shift;
my ($obj, $class) = ('', '');
my @refs;
my %refs;
while ($o->{content} =~ s/^\\(?:\((\w+)\))?((\%|\@|\$|\\).*)/$2/) {
push @refs, $1;
$refs{$1} = scalar @refs;
}
if ($o->{content} =~ /^([\%\@\$])
(\w(?:\w|::)*)?
\s*$/x
) {
my $foo;
$obj = ($1 eq '%') ? {} : ($1 eq '@') ? [] : \$foo;
$class = $2 || '';
if ($1 eq '%') {
%$obj = $o->_undent_hash;
}
elsif ($1 eq '@') {
@$obj = $o->_undent_array;
}
else {
$$obj = $o->_undent_scalar;
}
bless $obj, $class if length $class;
}
elsif ($o->{content} =~ /^\?\s*$/) {
$obj = $o->_undent_undef;
}
else {
$obj = $o->_undent_value;
}
while (@refs) {
my $ref = pop @refs;
my $copy = $obj;
$obj = \ $copy;
$o->{xref}{$ref} = $obj if $ref;
}
return $obj;
}
sub _undent_value {
my $o = shift;
my $value = '';
if ($o->{content} =~ /^\<\<(\w+)(\-?)\s*$/) {
my ($marker, $chomp) = ($1, $2);
my $line = $o->{line};
$o->_next_line;
while (not $o->{done} and
$o->{lines}[0] ne $marker) {
$value .= $o->{lines}[0] . "\n";
$o->_next_line;
}
croak M03_no_value_end_marker($marker, $line) if $o->{done};
chomp $value if $chomp;
}
elsif ($o->{content} =~ /^\"/) {
croak $o->M04_mismatched_quotes unless $o->{content} =~ /^\".*\"\s*$/;
($value = $o->{content}) =~ s/^\"|\"\s*$//g;
}
else {
$value = $o->{content};
}
$o->_next_line;
$o->_setup_line;
return $value;
}
sub _undent_hash {
my @values;
my $o = shift;
my $level = $o->{level} + 1;
$o->_next_line;
$o->_setup_line;
while ($o->{level} == $level) {
my ($key, $value) = split $o->{comma}, $o->{content};
croak $o->M05_invalid_key_value unless (defined $key and defined $value);
$o->{content} = $value;
push @values, $o->_get_key($key), $o->_undent_data;;
}
croak $o->M06_invalid_indent_level if $o->{level} > $level;
return @values;
}
sub _get_key {
my ($o, $key) = @_;
return $key unless $key =~ /^\<\<(\w+)(\-?)/;
my ($marker, $chomp) = ($1, $2);
$key = '';
my $line = $o->{line};
$o->_next_line;
while (not $o->{done} and
$o->{lines}[0] ne $marker) {
$key .= $o->{lines}[0] . "\n";
$o->_next_line;
}
croak M02_no_key_end_marker($marker, $line) if $o->{done};
chomp $key if $chomp;
$o->_next_line;
$o->_setup_line;
return $key;
}
sub _undent_array {
my @values;
my $o = shift;
my $level = $o->{level} + 1;
$o->_next_line;
$o->_setup_line;
while ($o->{level} == $level) {
push @values, $o->_undent_data;
}
croak $o->M06_invalid_indent_level if $o->{level} > $level;
return @values;
}
sub _undent_scalar {
my $values;
my $o = shift;
my $level = $o->{level} + 1;
$o->_next_line;
$o->_setup_line;
croak $o->M06_invalid_indent_level if $o->{level} != $level;
croak $o->M07_invalid_scalar_value if $o->{content} =~ /^[\%\@\$\\]/;
return $o->_undent_undef if $o->{content} =~ /^\?/;
return $o->_undent_value;
}
sub _undent_undef {
my $o = shift;
$o->_next_line;
$o->_setup_line;
return undef;
}
sub _next_line {
my $o = shift;
$o->{done}++, $o->{level} = -1, return unless @{$o->{lines}};
local $_ = shift @{$o->{lines}};
$o->{line}++;
}
sub _setup_line {
my $o = shift;
$o->{done}++, $o->{level} = -1, return unless @{$o->{lines}};
my ($width, $tabwidth) = @{$o}{qw(width tabwidth)};
while (1) {
local $_ = $o->{lines}[0];
# expand tabs in leading whitespace;
$o->next_line, next if /^(\s*$|\#)/; # skip comments and blank lines
while (s{^( *)(\t+)}
{' ' x (length($1) + length($2) * $tabwidth -
length($1) % $tabwidth)}e){}
croak $o->M01_invalid_indent_width unless /^(( {$width})*)(\S.*)$/;
$o->{level} = length($1) / $width;
$o->{content} = $3;
last;
}
}
1;
__END__
sub indent {
my $o = shift;
my $package = caller;
$package = caller(1) if $package eq 'Inline::denter';
my $stream = '';
$o->{key} = '';
while (@_) {
local $_ = shift;
$stream .= $o->indent_name($_, shift), next
if (/^\*$package\::\w+$/);
$stream .= $o->indent_data($_);
}
return $stream;
}
sub indent_data {
my $o = shift;
local $_ = shift;
return $o->indent_undef($_)
if not defined;
return $o->indent_value($_)
if (not ref);
return $o->indent_hash($_)
if (ref eq 'HASH' and not /=/ or /=HASH/);
return $o->indent_array($_)
if (ref eq 'ARRAY' and not /=/ or /=ARRAY/);
return $o->indent_scalar($_)
if (ref eq 'SCALAR' and not /=/ or /=SCALAR/);
return $o->indent_ref($_)
if (ref eq 'REF');
return "$_\n";
}
sub indent_value {
my ($o, $data) = @_;
my $stream;
if ($data =~ /\n/) {
my $marker = 'EOV';
$marker++ while $data =~ /^$marker$/m;
my $chomp = ($data =~ s/\n\Z//) ? '' : '-';
$stream = "<<$marker$chomp\n";
$stream .= $o->{key}, $o->{key} = '' if $o->{key};
$stream .= "$data\n$marker\n";
}
elsif ($data =~ /^[\s\%\@\$\\?\"]|\s$/ or
$data =~ /\Q$o->{comma}\E/ or
$data =~ /[\x00-\x1f]/ or
$data eq '') {
$stream = qq{"$data"\n};
$stream .= $o->{key}, $o->{key} = '' if $o->{key};
}
else {
$stream = "$data\n";
$stream .= $o->{key}, $o->{key} = '' if $o->{key};
}
return $stream;
}
sub indent_hash {
my ($o, $data) = @_;
my $stream = $o->_print_ref($data, '%', 'HASH');
return $$stream if ref $stream;
my $indent = ++$o->{level} * $o->{width};
for my $key (sort keys %$data) {
my $key_out = $key;
if ($key =~ /\n/ or
$key =~ /\Q$o->{comma}\E/) {
my $marker = 'EOK';
$marker++ while $key =~ /^$marker$/m;
my $chomp = (($o->{key} = $key) =~ s/\n\Z//m) ? '' : '-';
$o->{key} .= "\n$marker\n";
$key_out = "<<$marker$chomp";
}
elsif ($data =~ /^[\s\%\@\$\\?\"]|\s$/) {
$key_out = qq{"$key"};
}
$stream .= ' ' x $indent . $key_out . $o->{comma};
$stream .= $o->indent_data($data->{$key});
}
$o->{level}--;
return $stream;
}
sub indent_array {
my ($o, $data) = @_;
my $stream = $o->_print_ref($data, '@', 'ARRAY');
return $$stream if ref $stream;
my $indent = ++$o->{level} * $o->{width};
for my $datum (@$data) {
$stream .= ' ' x $indent;
$stream .= $o->indent_data($datum);
}
$o->{level}--;
return $stream;
}
sub indent_scalar {
my ($o, $data) = @_;
my $stream = $o->_print_ref($data, q{$}, 'SCALAR');
return $$stream if ref $stream;
my $indent = ($o->{level} + 1) * $o->{width};
$stream .= ' ' x $indent;
$stream .= $o->indent_data($$data);
return $stream;
}
sub indent_ref {
my ($o, $data) = @_;
my $stream = $o->_print_ref($data, '\\', 'SCALAR');
return $$stream if ref $stream;
chomp $stream;
return $stream . $o->indent_data($$data);
}
sub indent_undef {
my ($o, $data) = @_;
my $stream = "?\n";
$stream .= $o->{key}, $o->{key} = '' if $o->{key};
return $stream;
}
sub indent_name {
my ($o, $name, $value) = @_;
$name =~ s/^.*:://;
my $stream = $name . $o->{comma};
$stream .= $o->indent_data($value);
return $stream;
}
sub _print_ref {
my ($o, $data, $symbol, $type) = @_;
$data =~ /^(([\w:]+)=)?$type\(0x([0-9a-f]+)\)$/
or croak "Invalid reference: $data\n";
my $stream = $symbol;
$stream .= $2 if defined $2;
$o->{xref}{$3}++;
croak "Inline::denter does not handle duplicate references"
if $o->{xref}{$3} > 1;
$stream .= "\n";
$stream .= $o->{key}, $o->{key} = '' if $o->{key};
return $stream;
}
# Undent error messages
sub M01_invalid_indent_width {
my $o = shift;
"Invalid indent width detected at line $o->{line}\n";
}
sub M02_no_key_end_marker {
my ($marker, $line) = @_;
"No terminating marker '$marker' found for key at line $line\n";
}
sub M03_no_value_end_marker {
my ($marker, $line) = @_;
"No terminating marker '$marker' found for value at line $line\n";
}
sub M04_mismatched_quotes {
my $o = shift;
"Mismatched double quotes for value at line $o->{line}\n";
}
sub M05_invalid_key_value {
my $o = shift;
"Missing or invalid hash key/value pair at $o->{line}\n";
}
sub M06_invalid_indent_level {
my $o = shift;
"Invalid indentation level at $o->{line}\n";
}
sub M07_invalid_scalar_value {
my $o = shift;
"Invalid value for scalar ref context at $o->{line}\n";
}
1;
__END__
|