/usr/share/perl5/perl5i/1/SCALAR.pm is in libperl5i-perl 2.12.0-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 | # vi: set ts=4 sw=4 ht=4 et :
package perl5i::1::SCALAR;
use 5.010;
use strict;
use warnings;
require Carp;
use autobox;
use perl5i::1::autobox;
sub title_case {
my ($string) = @_;
$string =~ s/\b(\w)/\U$1/g;
return $string;
}
sub center {
my ($string, $size, $char) = @_;
Carp::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::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 ltrim {
my ($string,$trim_charset) = @_;
$trim_charset = '\s' unless defined $trim_charset;
my $re = qr/^[$trim_charset]*/;
$string =~ s/$re//;
return $string;
}
sub rtrim {
my ($string,$trim_charset) = @_;
$trim_charset = '\s' unless defined $trim_charset;
my $re = qr/[$trim_charset]*$/;
$string =~ s/$re//;
return $string;
}
sub trim {
my $charset = $_[1];
return rtrim(ltrim($_[0], $charset), $charset);
}
sub 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 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 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 is_tainted {
require Taint::Util;
return ref $_[0] ? Taint::Util::tainted(${$_[0]}) : Taint::Util::tainted($_[0]);
}
sub load {
require Module::Load;
goto &Module::Load::load;
}
sub alias {
Carp::croak(<<ERROR) if !ref $_[0];
Due to limitations in autoboxing, scalars cannot be aliased.
Sorry. Use a scalar reference instead.
ERROR
goto &perl5i::1::UNIVERSAL::alias;
}
require POSIX;
*ceil = \&POSIX::ceil;
*floor = \&POSIX::floor;
*round_up = \&ceil;
*round_down = \&floor;
sub round {
abs($_[0] - int($_[0])) < 0.5 ? round_down($_[0])
: round_up($_[0])
}
require Scalar::Util;
*is_number = \&Scalar::Util::looks_like_number;
sub is_positive { $_[0]->is_number && $_[0] > 0 }
sub is_negative { $_[0]->is_number && $_[0] < 0 }
sub is_integer { $_[0]->is_number && ((int($_[0]) - $_[0]) == 0) }
*is_int = \&is_integer;
sub is_decimal { $_[0]->is_number && ((int($_[0]) - $_[0]) != 0) }
sub path2module {
my $path = shift;
my($vol, $dirs, $file) = File::Spec->splitpath($path);
my @dirs = grep length, File::Spec->splitdir($dirs);
Carp::croak("'$path' does not look like a Perl module path")
if $file !~ m{\.pm$} or File::Spec->file_name_is_absolute($path);
$file =~ s{\.pm$}{};
return join "::", @dirs, $file;
}
sub module2path {
my $module = shift;
my @parts = split /::/, $module;
$parts[-1] .= ".pm";
return join "/", @parts;
}
1;
|