The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Fauxtobox - fake autoboxing (call methods on plain scalars)

SYNOPSIS

 use Fauxtobox;

 my $n = "zomg"->$_length;  # $n = 4
 print $n->$_sqrt;          # "2"

 # ... and many methods more

DESCRIPTION

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.

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.

Exported symbols

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);

Methods

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.

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.

$_apply

$X->$_apply($F) is equivalent to $F->($X), so e.g. "abc"->$_apply(\&display) is equivalent to display("abc").

$_list

$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.

$_qr

$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.

See "qr" in perlfunc.

$_m

$X->$_m($REGEX) is equivalent to $X =~ m/$REGEX/.

See "m" in perlfunc.

$_m_g

$X->$_m_g($REGEX) is equivalent to $X =~ m/$REGEX/g.

See "m" in perlfunc.

$_m_gc

$X->$_m_gc($REGEX) is equivalent to $X =~ m/$REGEX/gc.

See "m" in perlfunc.

$_s

$X->$_s($REGEX, $REPLACEMENT) is equivalent to $X =~ s/$REGEX/$REPLACEMENT->()/e if $REPLACEMENT is a subroutine reference and $X =~ s/$REGEX/$REPLACEMENT/ otherwise.

See "s" in perlfunc.

$_s_g

$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.

See "s" in perlfunc.

$_s_r

$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.

See "s" in perlfunc.

$_s_gr

$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.

See "s" in perlfunc.

$_test_r
$_test_w
$_test_x
$_test_o
$_test_R
$_test_W
$_test_X
$_test_O
$_test_e
$_test_z
$_test_s
$_test_f
$_test_d
$_test_l
$_test_p
$_test_S
$_test_b
$_test_c
$_test_t
$_test_u
$_test_g
$_test_k
$_test_T
$_test_B
$_test_M
$_test_A
$_test_C

These are file test operators. $X->$_test_X is equivalent to -X $X for all letters X listed above.

See "-X" in perlfunc.

$_abs

$X->$_abs is equivalent to abs $X.

See "abs" in perlfunc.

$_alarm

$X->$_alarm is equivalent to alarm $X.

See "alarm" in perlfunc.

$_atan2

$X->atan2($Y) is equivalent to atan2 $X, $Y.

See "atan2" in perlfunc.

$_bless

$X->$_bless($CLASS) is equivalent to bless $X, $CLASS. $X->$_bless is equivalent to bless $X.

See "bless" in perlfunc.

$_chdir

$X->$_chdir is equivalent to chdir $X.

See "chdir" in perlfunc.

$_chmod

$X->$_chmod($MODE) is equivalent to chmod $MODE, @{$X} if $X is an array reference and chmod $MODE, $X otherwise.

See "chmod" in perlfunc.

$_chomp

$X->$_chomp is equivalent to chomp @{$X} if $X is an array reference and chomp $X otherwise.

See "chomp" in perlfunc.

$_chop

$X->$_chop is equivalent to chop @{$X} if $X is an array reference and chop $X otherwise.

See "chop" in perlfunc.

$_chown

$X->$_chown($UID, $GID) is equivalent to chown $UID, $GID, @{$X} if $X is an array reference and chown $UID, $GID, $X otherwise.

See "chown" in perlfunc.

$_chr

$X->$_chr is equivalent to chr $X.

See "chr" in perlfunc.

$_chroot

$X->$_chroot is equivalent to chroot $X.

See "chroot" in perlfunc.

$_cos

$X->$_cos is equivalent to cos $X.

See "cos" in perlfunc.

$_crypt

$X->$_crypt($SALT) is equivalent to crypt $X, $SALT.

See "crypt" in perlfunc.

$_defined

$X->$_defined is equivalent to defined $X.

See "defined" in perlfunc.

$_delete

$X->$_delete($KEY) is equivalent to delete $X->[$KEY] if $X is an array reference and delete $X->{$KEY} otherwise.

See "delete" in perlfunc.

$_die

$X->$_die is equivalent to die $X.

See "die" in perlfunc.

$_each

$X->$_each is equivalent to each @{$X} if $X is an array reference and each %{$X} otherwise.

See "each" in perlfunc.

$_eval

$X->$_eval is equivalent to eval $X.

See "eval" in perlfunc.

$_exec

$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.

See "exec" in perlfunc.

$_exists

$X->$_exists($KEY) is equivalent to exists $X->[$KEY] if $X is an array reference and exists $X->{$KEY} otherwise.

See "exists" in perlfunc.

$_exit

$X->$_exit is equivalent to exit $X.

See "exit" in perlfunc.

$_exp

$X->$_exp is equivalent to exp $X.

See "exp" in perlfunc.

$_fc

$X->$_fc is equivalent to fc $X.

See "fc" in perlfunc.

$_getpgrp

$X->$_getpgrp is equivalent to getpgrp $X.

See "getpgrp" in perlfunc.

$_getpwnam

$X->$_getpwnam is equivalent to getpwnam $X.

See "getpwnam" in perlfunc.

$_getgrnam

$X->$_getgrnam is equivalent to getgrnam $X.

See "getgrnam" in perlfunc.

$_gethostbyname

$X->$_gethostbyname is equivalent to gethostbyname $X.

See "gethostbyname" in perlfunc.

$_getnetbyname

$X->$_getnetbyname is equivalent to getnetbyname $X.

See "getnetbyname" in perlfunc.

$_getprotobyname

$X->$_getprotobyname is equivalent to getprotobyname $X.

See "getprotobyname" in perlfunc.

$_getpwuid

$X->$_getpwuid is equivalent to getpwuid $X.

See "getpwuid" in perlfunc.

$_getgrgid

$X->$_getgrgid is equivalent to getgrgid $X.

See "getgrgid" in perlfunc.

$_getservbyname

$X->$_getservbyname($Y) is equivalent to getservbyname $X, $Y.

See "getservbyname" in perlfunc.

$_gethostbyaddr

$X->$_gethostbyaddr($Y) is equivalent to gethostbyaddr $X, $Y.

See "gethostbyaddr" in perlfunc.

$_getnetbyaddr

$X->$_getnetbyaddr($Y) is equivalent to getnetbyaddr $X, $Y.

See "getnetbyaddr" in perlfunc.

$_getprotobynumber

$X->$_getprotobynumber is equivalent to getprotobynumber $X.

See "getprotobynumber" in perlfunc.

$_getservbyport

$X->$_getservbyport($Y) is equivalent to getservbyport $X, $Y.

See "getservbyport" in perlfunc.

$_glob

$X->$_glob is equivalent to [ glob $X ], i.e. it returns an array reference of results.

See "glob" in perlfunc.

$_gmtime

$X->$_gmtime is equivalent to gmtime $X.

See "gmtime" in perlfunc.

$_grep

$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.

See "grep" in perlfunc.

$_hex

$X->$_hex is equivalent to hex $X.

See "hex" in perlfunc.

$_index

$X->$_index($NEEDLE) is equivalent to index $X, $NEEDLE. $X->$_index($NEEDLE, $OFFSET) is equivalent to index $X, $NEEDLE, $OFFSET.

See "index" in perlfunc.

$_int

$X->$_int is equivalent to int $X.

See "int" in perlfunc.

$_join

$X->$_join($SEP) is equivalent to join $SEP, @{$X}.

See "join" in perlfunc.

$_keys

$X->$_keys is equivalent to [ keys @{$X} ] if $X is an array reference and [ keys %{$X} ] otherwise.

See "keys" in perlfunc.

$_kill

$X->$_kill($SIGNAL) is equivalent to kill $SIGNAL, @{$X} if $X is an array reference and kill $SIGNAL, $X otherwise.

See "kill" in perlfunc.

$_lc

$X->$_lc is equivalent to lc $X.

See "lc" in perlfunc.

$_lcfirst

$X->$_lcfirst is equivalent to lcfirst $X.

See "lcfirst" in perlfunc.

$_length

$X->$_length is equivalent to length $X.

See "length" in perlfunc.

$X->$_link($Y) is equivalent to link $X, $Y.

See "link" in perlfunc.

$_localtime

$X->$_localtime is equivalent to localtime $X.

See "localtime" in perlfunc.

$_log

$X->$_log is equivalent to log $X.

See "log" in perlfunc.

$_lstat

$X->$_lstat is equivalent to lstat $X.

See "lstat" in perlfunc.

$_map

$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.

See "map" in perlfunc.

$_mkdir

$X->$_mkdir is equivalent to mkdir $X.

See "mkdir" in perlfunc.

$_oct

$X->$_oct is equivalent to oct $X.

See "oct" in perlfunc.

$_ord

$X->$_ord is equivalent to ord $X.

See "ord" in perlfunc.

$_pack

$X->$_pack($FORMAT) is equivalent to pack $FORMAT, @{$X} if $X is an array reference and pack $FORMAT, $X otherwise.

See "pack" in perlfunc.

$_pop

$X->$_pop is equivalent to pop @{$X}.

See "pop" in perlfunc.

$_pos

$X->$_pos is equivalent to pos $X. $X->$_pos($Y) is equivalent to pos($X) = $Y.

See "pos" in perlfunc.

$_prototype

$X->$_prototype is equivalent to prototype $X.

See "prototype" in perlfunc.

$_push

$X->$_push(@VALUES) is equivalent to push @{$X}, @VALUES.

See "push" in perlfunc.

$_quotemeta

$X->$_quotemeta is equivalent to quotemeta $X.

See "quotemeta" in perlfunc.

$_rand

$X->$_rand is equivalent to rand $X.

See "rand" in perlfunc.

$X->$_readlink is equivalent to readlink $X.

See "readlink" in perlfunc.

$_ref

$X->$_ref is equivalent to ref $X.

See "ref" in perlfunc.

$_rename

$X->$_rename($Y) is equivalent to rename $X, $Y.

See "rename" in perlfunc.

$_require

$X->$_require is equivalent to require $X.

See "require" in perlfunc.

$_reverse

$X->$_reverse is equivalent to [ reverse @{$X} ] if $X is an array reference and scalar reverse $X otherwise.

See "reverse" in perlfunc.

$_rindex

$X->$_rindex($NEEDLE) is equivalent to rindex $X, $NEEDLE. $X->$_rindex($NEEDLE, $OFFSET) is equivalent to rindex $X, $NEEDLE, $OFFSET.

See "rindex" in perlfunc.

$_rmdir

$X->$_rmdir is equivalent to rmdir $X.

See "rmdir" in perlfunc.

$_shift

$X->$_shift is equivalent to shift @{$X}.

See "shift" in perlfunc.

$_sin

$X->$_sin is equivalent to sin $X.

See "sin" in perlfunc.

$_sleep

$X->$_sleep is equivalent to sleep $X.

See "sleep" in perlfunc.

$_sort

$X->$_sort is equivalent to [ sort @{$X} ]. $X->$_sort($CMP) is equivalent to [ sort { $CMP->($a, $b) } @{$X} ].

See "sort" in perlfunc.

$_splice

$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.

See "splice" in perlfunc.

$_split

$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 ].

See "split" in perlfunc.

$_sprintf

$X->$_sprintf($FORMAT) is equivalent to sprintf $FORMAT, @{$X} if $X is an array reference and sprintf $FORMAT, $X otherwise.

See "sprintf" in perldoc.

$_sqrt

$X->$_sqrt is equivalent to sqrt $X.

See "sqrt" in perlfunc.

$_srand

$X->$_srand is equivalent to srand $X.

See "srand" in perlfunc.

$_stat

$X->$_stat is equivalent to stat $X.

See "stat" in perlfunc.

$_substr

$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.

See "substr" in perlfunc.

$X->$_symlink($Y) is equivalent to symlink $X, $Y.

See "symlink" in perlfunc.

$_syscall

$X->$_syscall(@ARGS) is equivalent to syscall $X, @ARGS.

See "syscall" in perlfunc.

$_system

$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.

See "system" in perlfunc.

$_truncate

$X->$_truncate($Y) is equivalent to truncate $X, $Y.

See "truncate" in perlfunc.

$_uc

$X->$_uc is equivalent to uc $X.

See "uc" in perlfunc.

$_ucfirst

$X->$_ucfirst is equivalent to ucfirst $X.

See "ucfirst" in perlfunc.

$_umask

$X->$_umask is equivalent to umask $X.

See "umask" in perlfunc.

$X->$_unlink is equivalent to unlink $X.

See "unlink" in perlfunc.

$_unpack

$X->$_unpack($FORMAT) is equivalent to unpack $FORMAT, $X.

See "unpack" in perlfunc.

$_unshift

$X->$_unshift(@VALUES) is equivalent to unshift @{$X}, @VALUES.

See "unshift" in perlfunc.

$_utime

$X->$_utime($ATIME, $MTIME) is equivalent to utime $ATIME, $MTIME, @{$X} if $X is an array reference and utime $ATIME, $MTIME, $X otherwise.

See "utime" in perlfunc.

$_values

$X->$_values is equivalent to [ values @{$X} ] if $X is an array reference and [ values %{$X} ] otherwise.

See "values" in perlfunc.

$_vec

$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.

See "vec" in perlfunc.

$_waitpid

$X->$_waitpid is equivalent to waitpid $X, 0. $X->$_waitpid($FLAGS) is equivalent to waitpid $X, $FLAGS.

See "waitpid" in perlfunc.

$_warn

$X->$_warn is equivalent to warn $X.

See "warn" in perlfunc.

SEE ALSO

autobox

AUTHOR

Lukas Mai, <l.mai at web.de>

COPYRIGHT & LICENSE

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.