Fauxtobox - fake autoboxing (call methods on plain scalars)
use Fauxtobox; my $n = "zomg"->$_length; # $n = 4 print $n->$_sqrt; # "2" # ... and many methods more
This module provides fake autoboxing support. Autoboxing means being able to call methods on non-objects like 42 or 'hello' because the language will automatically wrap them in objects. If you want that, see autobox.
42
'hello'
What this module does is much simpler: It exports a bunch of variables that can be used like methods. These method variables can be used on any value, not just objects.
By default everything listed below is exported. If you don't want that, you can explicitly list the variables you want:
use Fauxtobox qw($_defined $_length $_apply);
For convenience you can omit the leading $_ in the import list:
$_
use Fauxtobox qw(defined length apply);
If you call any of these fake methods on a real object, it will simply forward to a method of the same name, i.e. $obj->$_foo(...) is equivalent to $obj->foo(...) if $obj is blessed.
$obj->$_foo(...)
$obj->foo(...)
$obj
Several functions in Perl take or return lists. In general, the method equivalents of these take and return array references instead, to make method chaining possible. Exceptions are noted below.
$X->$_apply($F) is equivalent to $F->($X), so e.g. "abc"->$_apply(\&display) is equivalent to display("abc").
$X->$_apply($F)
$F->($X)
"abc"->$_apply(\&display)
display("abc")
$X->$_list returns %{$X} if $X is a hash reference and @{$X} otherwise. This is useful if you have an array reference and want to turn it into a list of its values.
$X->$_list
%{$X}
$X
@{$X}
$X->$_qr is equivalent to qr/$X/. $X->$_qr($FLAGS) is equivalent to qr/$X/$FLAGS except that's a syntax error, but e.g. '^hello\s+world'->$_qr('i') is equivalent to qr/^hello\s+world/i.
$X->$_qr
qr/$X/
$X->$_qr($FLAGS)
qr/$X/$FLAGS
'^hello\s+world'->$_qr('i')
qr/^hello\s+world/i
See "qr" in perlfunc.
$X->$_m($REGEX) is equivalent to $X =~ m/$REGEX/.
$X->$_m($REGEX)
$X =~ m/$REGEX/
See "m" in perlfunc.
$X->$_m_g($REGEX) is equivalent to $X =~ m/$REGEX/g.
$X->$_m_g($REGEX)
$X =~ m/$REGEX/g
$X->$_m_gc($REGEX) is equivalent to $X =~ m/$REGEX/gc.
$X->$_m_gc($REGEX)
$X =~ m/$REGEX/gc
$X->$_s($REGEX, $REPLACEMENT) is equivalent to $X =~ s/$REGEX/$REPLACEMENT->()/e if $REPLACEMENT is a subroutine reference and $X =~ s/$REGEX/$REPLACEMENT/ otherwise.
$X->$_s($REGEX, $REPLACEMENT)
$X =~ s/$REGEX/$REPLACEMENT->()/e
$REPLACEMENT
$X =~ s/$REGEX/$REPLACEMENT/
See "s" in perlfunc.
$X->$_s_g($REGEX, $REPLACEMENT) is equivalent to $X =~ s/$REGEX/$REPLACEMENT->()/ge if $REPLACEMENT is a subroutine reference and $X =~ s/$REGEX/$REPLACEMENT/g otherwise.
$X->$_s_g($REGEX, $REPLACEMENT)
$X =~ s/$REGEX/$REPLACEMENT->()/ge
$X =~ s/$REGEX/$REPLACEMENT/g
$X->$_s_r($REGEX, $REPLACEMENT) is equivalent to $X =~ s/$REGEX/$REPLACEMENT->()/re if $REPLACEMENT is a subroutine reference and $X =~ s/$REGEX/$REPLACEMENT/r otherwise.
$X->$_s_r($REGEX, $REPLACEMENT)
$X =~ s/$REGEX/$REPLACEMENT->()/re
$X =~ s/$REGEX/$REPLACEMENT/r
$X->$_s($REGEX, $REPLACEMENT) is equivalent to $X =~ s/$REGEX/$REPLACEMENT->()/gre if $REPLACEMENT is a subroutine reference and $X =~ s/$REGEX/$REPLACEMENT/gr otherwise.
$X =~ s/$REGEX/$REPLACEMENT->()/gre
$X =~ s/$REGEX/$REPLACEMENT/gr
These are file test operators. $X->$_test_X is equivalent to -X $X for all letters X listed above.
$X->$_test_X
-X $X
See "-X" in perlfunc.
$X->$_abs is equivalent to abs $X.
$X->$_abs
abs $X
See "abs" in perlfunc.
$X->$_alarm is equivalent to alarm $X.
$X->$_alarm
alarm $X
See "alarm" in perlfunc.
$X->atan2($Y) is equivalent to atan2 $X, $Y.
$X->atan2($Y)
atan2 $X, $Y
See "atan2" in perlfunc.
$X->$_bless($CLASS) is equivalent to bless $X, $CLASS. $X->$_bless is equivalent to bless $X.
$X->$_bless($CLASS)
bless $X, $CLASS
$X->$_bless
bless $X
See "bless" in perlfunc.
$X->$_chdir is equivalent to chdir $X.
$X->$_chdir
chdir $X
See "chdir" in perlfunc.
$X->$_chmod($MODE) is equivalent to chmod $MODE, @{$X} if $X is an array reference and chmod $MODE, $X otherwise.
$X->$_chmod($MODE)
chmod $MODE, @{$X}
chmod $MODE, $X
See "chmod" in perlfunc.
$X->$_chomp is equivalent to chomp @{$X} if $X is an array reference and chomp $X otherwise.
$X->$_chomp
chomp @{$X}
chomp $X
See "chomp" in perlfunc.
$X->$_chop is equivalent to chop @{$X} if $X is an array reference and chop $X otherwise.
$X->$_chop
chop @{$X}
chop $X
See "chop" in perlfunc.
$X->$_chown($UID, $GID) is equivalent to chown $UID, $GID, @{$X} if $X is an array reference and chown $UID, $GID, $X otherwise.
$X->$_chown($UID, $GID)
chown $UID, $GID, @{$X}
chown $UID, $GID, $X
See "chown" in perlfunc.
$X->$_chr is equivalent to chr $X.
$X->$_chr
chr $X
See "chr" in perlfunc.
$X->$_chroot is equivalent to chroot $X.
$X->$_chroot
chroot $X
See "chroot" in perlfunc.
$X->$_cos is equivalent to cos $X.
$X->$_cos
cos $X
See "cos" in perlfunc.
$X->$_crypt($SALT) is equivalent to crypt $X, $SALT.
$X->$_crypt($SALT)
crypt $X, $SALT
See "crypt" in perlfunc.
$X->$_defined is equivalent to defined $X.
$X->$_defined
defined $X
See "defined" in perlfunc.
$X->$_delete($KEY) is equivalent to delete $X->[$KEY] if $X is an array reference and delete $X->{$KEY} otherwise.
$X->$_delete($KEY)
delete $X->[$KEY]
delete $X->{$KEY}
See "delete" in perlfunc.
$X->$_die is equivalent to die $X.
$X->$_die
die $X
See "die" in perlfunc.
$X->$_each is equivalent to each @{$X} if $X is an array reference and each %{$X} otherwise.
$X->$_each
each @{$X}
each %{$X}
See "each" in perlfunc.
$X->$_eval is equivalent to eval $X.
$X->$_eval
eval $X
See "eval" in perlfunc.
$X->$_exec(@ARGS) is equivalent to exec { $X } @ARGS. $X->$_exec is equivalent to exec @{$X} if $X is an array reference and exec $X otherwise.
$X->$_exec(@ARGS)
exec { $X } @ARGS
$X->$_exec
exec @{$X}
exec $X
See "exec" in perlfunc.
$X->$_exists($KEY) is equivalent to exists $X->[$KEY] if $X is an array reference and exists $X->{$KEY} otherwise.
$X->$_exists($KEY)
exists $X->[$KEY]
exists $X->{$KEY}
See "exists" in perlfunc.
$X->$_exit is equivalent to exit $X.
$X->$_exit
exit $X
See "exit" in perlfunc.
$X->$_exp is equivalent to exp $X.
$X->$_exp
exp $X
See "exp" in perlfunc.
$X->$_fc is equivalent to fc $X.
$X->$_fc
fc $X
See "fc" in perlfunc.
$X->$_getpgrp is equivalent to getpgrp $X.
$X->$_getpgrp
getpgrp $X
See "getpgrp" in perlfunc.
$X->$_getpwnam is equivalent to getpwnam $X.
$X->$_getpwnam
getpwnam $X
See "getpwnam" in perlfunc.
$X->$_getgrnam is equivalent to getgrnam $X.
$X->$_getgrnam
getgrnam $X
See "getgrnam" in perlfunc.
$X->$_gethostbyname is equivalent to gethostbyname $X.
$X->$_gethostbyname
gethostbyname $X
See "gethostbyname" in perlfunc.
$X->$_getnetbyname is equivalent to getnetbyname $X.
$X->$_getnetbyname
getnetbyname $X
See "getnetbyname" in perlfunc.
$X->$_getprotobyname is equivalent to getprotobyname $X.
$X->$_getprotobyname
getprotobyname $X
See "getprotobyname" in perlfunc.
$X->$_getpwuid is equivalent to getpwuid $X.
$X->$_getpwuid
getpwuid $X
See "getpwuid" in perlfunc.
$X->$_getgrgid is equivalent to getgrgid $X.
$X->$_getgrgid
getgrgid $X
See "getgrgid" in perlfunc.
$X->$_getservbyname($Y) is equivalent to getservbyname $X, $Y.
$X->$_getservbyname($Y)
getservbyname $X, $Y
See "getservbyname" in perlfunc.
$X->$_gethostbyaddr($Y) is equivalent to gethostbyaddr $X, $Y.
$X->$_gethostbyaddr($Y)
gethostbyaddr $X, $Y
See "gethostbyaddr" in perlfunc.
$X->$_getnetbyaddr($Y) is equivalent to getnetbyaddr $X, $Y.
$X->$_getnetbyaddr($Y)
getnetbyaddr $X, $Y
See "getnetbyaddr" in perlfunc.
$X->$_getprotobynumber is equivalent to getprotobynumber $X.
$X->$_getprotobynumber
getprotobynumber $X
See "getprotobynumber" in perlfunc.
$X->$_getservbyport($Y) is equivalent to getservbyport $X, $Y.
$X->$_getservbyport($Y)
getservbyport $X, $Y
See "getservbyport" in perlfunc.
$X->$_glob is equivalent to [ glob $X ], i.e. it returns an array reference of results.
$X->$_glob
[ glob $X ]
See "glob" in perlfunc.
$X->$_gmtime is equivalent to gmtime $X.
$X->$_gmtime
gmtime $X
See "gmtime" in perlfunc.
$X->$_grep($F) is equivalent to [ grep $F->($_), @{$X} ], i.e. it takes and returns an array reference. The function $F is passed the current element as an argument.
$X->$_grep($F)
[ grep $F->($_), @{$X} ]
$F
See "grep" in perlfunc.
$X->$_hex is equivalent to hex $X.
$X->$_hex
hex $X
See "hex" in perlfunc.
$X->$_index($NEEDLE) is equivalent to index $X, $NEEDLE. $X->$_index($NEEDLE, $OFFSET) is equivalent to index $X, $NEEDLE, $OFFSET.
$X->$_index($NEEDLE)
index $X, $NEEDLE
$X->$_index($NEEDLE, $OFFSET)
index $X, $NEEDLE, $OFFSET
See "index" in perlfunc.
$X->$_int is equivalent to int $X.
$X->$_int
int $X
See "int" in perlfunc.
$X->$_join($SEP) is equivalent to join $SEP, @{$X}.
$X->$_join($SEP)
join $SEP, @{$X}
See "join" in perlfunc.
$X->$_keys is equivalent to [ keys @{$X} ] if $X is an array reference and [ keys %{$X} ] otherwise.
$X->$_keys
[ keys @{$X} ]
[ keys %{$X} ]
See "keys" in perlfunc.
$X->$_kill($SIGNAL) is equivalent to kill $SIGNAL, @{$X} if $X is an array reference and kill $SIGNAL, $X otherwise.
$X->$_kill($SIGNAL)
kill $SIGNAL, @{$X}
kill $SIGNAL, $X
See "kill" in perlfunc.
$X->$_lc is equivalent to lc $X.
$X->$_lc
lc $X
See "lc" in perlfunc.
$X->$_lcfirst is equivalent to lcfirst $X.
$X->$_lcfirst
lcfirst $X
See "lcfirst" in perlfunc.
$X->$_length is equivalent to length $X.
$X->$_length
length $X
See "length" in perlfunc.
$X->$_link($Y) is equivalent to link $X, $Y.
$X->$_link($Y)
link $X, $Y
See "link" in perlfunc.
$X->$_localtime is equivalent to localtime $X.
$X->$_localtime
localtime $X
See "localtime" in perlfunc.
$X->$_log is equivalent to log $X.
$X->$_log
log $X
See "log" in perlfunc.
$X->$_lstat is equivalent to lstat $X.
$X->$_lstat
lstat $X
See "lstat" in perlfunc.
$X->$_map($F) is equivalent to [ map $F->($_), @{$X} ], i.e. it takes and returns an array reference. The function $F is passed the current element as an argument.
$X->$_map($F)
[ map $F->($_), @{$X} ]
See "map" in perlfunc.
$X->$_mkdir is equivalent to mkdir $X.
$X->$_mkdir
mkdir $X
See "mkdir" in perlfunc.
$X->$_oct is equivalent to oct $X.
$X->$_oct
oct $X
See "oct" in perlfunc.
$X->$_ord is equivalent to ord $X.
$X->$_ord
ord $X
See "ord" in perlfunc.
$X->$_pack($FORMAT) is equivalent to pack $FORMAT, @{$X} if $X is an array reference and pack $FORMAT, $X otherwise.
$X->$_pack($FORMAT)
pack $FORMAT, @{$X}
pack $FORMAT, $X
See "pack" in perlfunc.
$X->$_pop is equivalent to pop @{$X}.
$X->$_pop
pop @{$X}
See "pop" in perlfunc.
$X->$_pos is equivalent to pos $X. $X->$_pos($Y) is equivalent to pos($X) = $Y.
$X->$_pos
pos $X
$X->$_pos($Y)
pos($X) = $Y
See "pos" in perlfunc.
$X->$_prototype is equivalent to prototype $X.
$X->$_prototype
prototype $X
See "prototype" in perlfunc.
$X->$_push(@VALUES) is equivalent to push @{$X}, @VALUES.
$X->$_push(@VALUES)
push @{$X}, @VALUES
See "push" in perlfunc.
$X->$_quotemeta is equivalent to quotemeta $X.
$X->$_quotemeta
quotemeta $X
See "quotemeta" in perlfunc.
$X->$_rand is equivalent to rand $X.
$X->$_rand
rand $X
See "rand" in perlfunc.
$X->$_readlink is equivalent to readlink $X.
$X->$_readlink
readlink $X
See "readlink" in perlfunc.
$X->$_ref is equivalent to ref $X.
$X->$_ref
ref $X
See "ref" in perlfunc.
$X->$_rename($Y) is equivalent to rename $X, $Y.
$X->$_rename($Y)
rename $X, $Y
See "rename" in perlfunc.
$X->$_require is equivalent to require $X.
$X->$_require
require $X
See "require" in perlfunc.
$X->$_reverse is equivalent to [ reverse @{$X} ] if $X is an array reference and scalar reverse $X otherwise.
$X->$_reverse
[ reverse @{$X} ]
scalar reverse $X
See "reverse" in perlfunc.
$X->$_rindex($NEEDLE) is equivalent to rindex $X, $NEEDLE. $X->$_rindex($NEEDLE, $OFFSET) is equivalent to rindex $X, $NEEDLE, $OFFSET.
$X->$_rindex($NEEDLE)
rindex $X, $NEEDLE
$X->$_rindex($NEEDLE, $OFFSET)
rindex $X, $NEEDLE, $OFFSET
See "rindex" in perlfunc.
$X->$_rmdir is equivalent to rmdir $X.
$X->$_rmdir
rmdir $X
See "rmdir" in perlfunc.
$X->$_shift is equivalent to shift @{$X}.
$X->$_shift
shift @{$X}
See "shift" in perlfunc.
$X->$_sin is equivalent to sin $X.
$X->$_sin
sin $X
See "sin" in perlfunc.
$X->$_sleep is equivalent to sleep $X.
$X->$_sleep
sleep $X
See "sleep" in perlfunc.
$X->$_sort is equivalent to [ sort @{$X} ]. $X->$_sort($CMP) is equivalent to [ sort { $CMP->($a, $b) } @{$X} ].
$X->$_sort
[ sort @{$X} ]
$X->$_sort($CMP)
[ sort { $CMP->($a, $b) } @{$X} ]
See "sort" in perlfunc.
$X->$_splice is equivalent to splice @{$X}. $X->$_splice($OFFSET) is equivalent to splice @{$X}, $OFFSET. $X->$_splice($OFFSET, $LENGTH) is equivalent to splice @{$X}, $OFFSET, $LENGTH. $X->$_splice($OFFSET, $LENGTH, @VALUES) is equivalent to splice @{$X}, $OFFSET, $LENGTH, @VALUES.
$X->$_splice
splice @{$X}
$X->$_splice($OFFSET)
splice @{$X}, $OFFSET
$X->$_splice($OFFSET, $LENGTH)
splice @{$X}, $OFFSET, $LENGTH
$X->$_splice($OFFSET, $LENGTH, @VALUES)
splice @{$X}, $OFFSET, $LENGTH, @VALUES
See "splice" in perlfunc.
$X->$_split is equivalent to [ split ' ', $X ]. $X->$_split($REGEX) is equivalent to [ split $REGEX, $X ]. $X->$_split($REGEX, $LIMIT) is equivalent to [ split $REGEX, $X, $LIMIT ].
$X->$_split
[ split ' ', $X ]
$X->$_split($REGEX)
[ split $REGEX, $X ]
$X->$_split($REGEX, $LIMIT)
[ split $REGEX, $X, $LIMIT ]
See "split" in perlfunc.
$X->$_sprintf($FORMAT) is equivalent to sprintf $FORMAT, @{$X} if $X is an array reference and sprintf $FORMAT, $X otherwise.
$X->$_sprintf($FORMAT)
sprintf $FORMAT, @{$X}
sprintf $FORMAT, $X
See "sprintf" in perldoc.
$X->$_sqrt is equivalent to sqrt $X.
$X->$_sqrt
sqrt $X
See "sqrt" in perlfunc.
$X->$_srand is equivalent to srand $X.
$X->$_srand
srand $X
See "srand" in perlfunc.
$X->$_stat is equivalent to stat $X.
$X->$_stat
stat $X
See "stat" in perlfunc.
$X->$_substr($OFFSET) is equivalent to substr $X, $OFFSET. $X->$_substr($OFFSET, $LENGTH) is equivalent to substr $X, $OFFSET, $LENGTH. $X->$_substr($OFFSET, $LENGTH, $REPLACEMENT) is equivalent to substr $X, $OFFSET, $LENGTH, $REPLACEMENT.
$X->$_substr($OFFSET)
substr $X, $OFFSET
$X->$_substr($OFFSET, $LENGTH)
substr $X, $OFFSET, $LENGTH
$X->$_substr($OFFSET, $LENGTH, $REPLACEMENT)
substr $X, $OFFSET, $LENGTH, $REPLACEMENT
See "substr" in perlfunc.
$X->$_symlink($Y) is equivalent to symlink $X, $Y.
$X->$_symlink($Y)
symlink $X, $Y
See "symlink" in perlfunc.
$X->$_syscall(@ARGS) is equivalent to syscall $X, @ARGS.
$X->$_syscall(@ARGS)
syscall $X, @ARGS
See "syscall" in perlfunc.
$X->$_system(@ARGS) is equivalent to system { $X } @ARGS. $X->$_system is equivalent to system @{$X} if $X is an array reference and system $X otherwise.
$X->$_system(@ARGS)
system { $X } @ARGS
$X->$_system
system @{$X}
system $X
See "system" in perlfunc.
$X->$_truncate($Y) is equivalent to truncate $X, $Y.
$X->$_truncate($Y)
truncate $X, $Y
See "truncate" in perlfunc.
$X->$_uc is equivalent to uc $X.
$X->$_uc
uc $X
See "uc" in perlfunc.
$X->$_ucfirst is equivalent to ucfirst $X.
$X->$_ucfirst
ucfirst $X
See "ucfirst" in perlfunc.
$X->$_umask is equivalent to umask $X.
$X->$_umask
umask $X
See "umask" in perlfunc.
$X->$_unlink is equivalent to unlink $X.
$X->$_unlink
unlink $X
See "unlink" in perlfunc.
$X->$_unpack($FORMAT) is equivalent to unpack $FORMAT, $X.
$X->$_unpack($FORMAT)
unpack $FORMAT, $X
See "unpack" in perlfunc.
$X->$_unshift(@VALUES) is equivalent to unshift @{$X}, @VALUES.
$X->$_unshift(@VALUES)
unshift @{$X}, @VALUES
See "unshift" in perlfunc.
$X->$_utime($ATIME, $MTIME) is equivalent to utime $ATIME, $MTIME, @{$X} if $X is an array reference and utime $ATIME, $MTIME, $X otherwise.
$X->$_utime($ATIME, $MTIME)
utime $ATIME, $MTIME, @{$X}
utime $ATIME, $MTIME, $X
See "utime" in perlfunc.
$X->$_values is equivalent to [ values @{$X} ] if $X is an array reference and [ values %{$X} ] otherwise.
$X->$_values
[ values @{$X} ]
[ values %{$X} ]
See "values" in perlfunc.
$X->$_vec($OFFSET, $BITS) is equivalent to vec $X, $OFFSET, $BITS. $X->$_vec($OFFSET, $BITS, $REPLACEMENT) is equivalent to c<< vec($X, $OFFSET, $BITS) = $REPLACEMENT.
$X->$_vec($OFFSET, $BITS)
vec $X, $OFFSET, $BITS
$X->$_vec($OFFSET, $BITS, $REPLACEMENT) is equivalent to c<< vec($X, $OFFSET, $BITS) = $REPLACEMENT
See "vec" in perlfunc.
$X->$_waitpid is equivalent to waitpid $X, 0. $X->$_waitpid($FLAGS) is equivalent to waitpid $X, $FLAGS.
$X->$_waitpid
waitpid $X, 0
$X->$_waitpid($FLAGS)
waitpid $X, $FLAGS
See "waitpid" in perlfunc.
$X->$_warn is equivalent to warn $X.
$X->$_warn
warn $X
See "warn" in perlfunc.
autobox
Lukas Mai, <l.mai at web.de>
<l.mai at web.de>
Copyright 2013-2014 Lukas Mai.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install Fauxtobox, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Fauxtobox
CPAN shell
perl -MCPAN -e shell install Fauxtobox
For more information on module installation, please visit the detailed CPAN module installation guide.