/usr/share/perl5/perl5i/0/SCALAR.pm is in libperl5i-perl 2.13.1-3.
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 | # vi: set ts=4 sw=4 ht=4 et :
package perl5i::0::SCALAR;
use 5.010;
use strict;
use warnings;
use Carp;
use autobox;
sub SCALAR::title_case {
my ($string) = @_;
$string =~ s/\b(\w)/\U$1/g;
return $string;
}
sub SCALAR::center {
my ($string, $size, $char) = @_;
carp "Use of uninitialized value for size in center()" if !defined $size;
$size //= 0;
$char //= ' ';
if (length $char > 1) {
my $bad = $char;
$char = substr $char, 0, 1;
carp "'$bad' is longer than one character, using '$char' instead";
}
my $len = length $string;
return $string if $size <= $len;
my $padlen = $size - $len;
# pad right with half the remaining characters
my $rpad = int( $padlen / 2 );
# bias the left padding to one more space, if $size - $len is odd
my $lpad = $padlen - $rpad;
return $char x $lpad . $string . $char x $rpad;
}
sub SCALAR::ltrim {
my ($string,$trim_charset) = @_;
$trim_charset = '\s' unless defined $trim_charset;
my $re = qr/^[$trim_charset]*/;
$string =~ s/$re//;
return $string;
}
sub SCALAR::rtrim {
my ($string,$trim_charset) = @_;
$trim_charset = '\s' unless defined $trim_charset;
my $re = qr/[$trim_charset]*$/;
$string =~ s/$re//;
return $string;
}
sub SCALAR::trim {
my $charset = $_[1];
return SCALAR::rtrim(SCALAR::ltrim($_[0], $charset), $charset);
}
sub SCALAR::wrap {
my ($string, %args) = @_;
my $width = $args{width} // 76;
my $separator = $args{separator} // "\n";
return $string if $width <= 0;
require Text::Wrap;
local $Text::Wrap::separator = $separator;
local $Text::Wrap::columns = $width;
return Text::Wrap::wrap('', '', $string);
}
# untaint the scalar itself, not the reference
sub SCALAR::untaint {
return $_[0]->mo->untaint if ref $_[0];
require Taint::Util;
Taint::Util::untaint($_[0]);
return 1;
}
# untaint the scalar itself, not the reference
sub SCALAR::taint {
return $_[0]->mo->taint if ref $_[0];
require Taint::Util;
Taint::Util::taint($_[0]);
return 1;
}
# Could use the version in Meta but this removes the need to check
# for overloading.
sub SCALAR::is_tainted {
require Taint::Util;
return ref $_[0] ? Taint::Util::tainted(${$_[0]}) : Taint::Util::tainted($_[0]);
}
sub SCALAR::load {
require Module::Load;
goto &Module::Load::load;
}
sub SCALAR::alias {
croak <<ERROR if !ref $_[0];
Due to limitations in autoboxing, scalars cannot be aliased.
Sorry. Use a scalar reference instead.
ERROR
goto &DEFAULT::alias;
}
require POSIX;
*SCALAR::ceil = \&POSIX::ceil;
*SCALAR::floor = \&POSIX::floor;
*SCALAR::round_up = \&SCALAR::ceil;
*SCALAR::round_down = \&SCALAR::floor;
sub SCALAR::round {
abs($_[0] - int($_[0])) < 0.5 ? SCALAR::round_down($_[0])
: SCALAR::round_up($_[0])
}
require Scalar::Util;
*SCALAR::is_number = \&Scalar::Util::looks_like_number;
sub SCALAR::is_positive { $_[0]->is_number && $_[0] > 0 }
sub SCALAR::is_negative { $_[0]->is_number && $_[0] < 0 }
sub SCALAR::is_integer { $_[0]->is_number && ((int($_[0]) - $_[0]) == 0) }
*SCALAR::is_int = \&SCALAR::is_integer;
sub SCALAR::is_decimal { $_[0]->is_number && ((int($_[0]) - $_[0]) != 0) }
1;
|