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 todisplay("abc"). - $_list
-
$X->$_listreturns%{$X}if$Xis 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->$_qris equivalent toqr/$X/.$X->$_qr($FLAGS)is equivalent toqr/$X/$FLAGSexcept that's a syntax error, but e.g.'^hello\s+world'->$_qr('i')is equivalent toqr/^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->()/eif$REPLACEMENTis 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->()/geif$REPLACEMENTis a subroutine reference and$X =~ s/$REGEX/$REPLACEMENT/gotherwise.See "s" in perlfunc.
- $_s_r
-
$X->$_s_r($REGEX, $REPLACEMENT)is equivalent to$X =~ s/$REGEX/$REPLACEMENT->()/reif$REPLACEMENTis a subroutine reference and$X =~ s/$REGEX/$REPLACEMENT/rotherwise.See "s" in perlfunc.
- $_s_gr
-
$X->$_s($REGEX, $REPLACEMENT)is equivalent to$X =~ s/$REGEX/$REPLACEMENT->()/greif$REPLACEMENTis a subroutine reference and$X =~ s/$REGEX/$REPLACEMENT/grotherwise.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_Xis equivalent to-X $Xfor all letters X listed above.See "-X" in perlfunc.
- $_abs
-
$X->$_absis equivalent toabs $X.See "abs" in perlfunc.
- $_alarm
-
$X->$_alarmis equivalent toalarm $X.See "alarm" in perlfunc.
- $_atan2
-
$X->atan2($Y)is equivalent toatan2 $X, $Y.See "atan2" in perlfunc.
- $_bless
-
$X->$_bless($CLASS)is equivalent tobless $X, $CLASS.$X->$_blessis equivalent tobless $X.See "bless" in perlfunc.
- $_chdir
-
$X->$_chdiris equivalent tochdir $X.See "chdir" in perlfunc.
- $_chmod
-
$X->$_chmod($MODE)is equivalent tochmod $MODE, @{$X}if$Xis an array reference andchmod $MODE, $Xotherwise.See "chmod" in perlfunc.
- $_chomp
-
$X->$_chompis equivalent tochomp @{$X}if$Xis an array reference andchomp $Xotherwise.See "chomp" in perlfunc.
- $_chop
-
$X->$_chopis equivalent tochop @{$X}if$Xis an array reference andchop $Xotherwise.See "chop" in perlfunc.
- $_chown
-
$X->$_chown($UID, $GID)is equivalent tochown $UID, $GID, @{$X}if$Xis an array reference andchown $UID, $GID, $Xotherwise.See "chown" in perlfunc.
- $_chr
-
$X->$_chris equivalent tochr $X.See "chr" in perlfunc.
- $_chroot
-
$X->$_chrootis equivalent tochroot $X.See "chroot" in perlfunc.
- $_cos
-
$X->$_cosis equivalent tocos $X.See "cos" in perlfunc.
- $_crypt
-
$X->$_crypt($SALT)is equivalent tocrypt $X, $SALT.See "crypt" in perlfunc.
- $_defined
-
$X->$_definedis equivalent todefined $X. - $_delete
-
$X->$_delete($KEY)is equivalent todelete $X->[$KEY]if $X is an array reference anddelete $X->{$KEY}otherwise.See "delete" in perlfunc.
- $_die
-
$X->$_dieis equivalent todie $X.See "die" in perlfunc.
- $_each
-
$X->$_eachis equivalent toeach @{$X}if$Xis an array reference andeach %{$X}otherwise.See "each" in perlfunc.
- $_eval
-
$X->$_evalis equivalent toeval $X.See "eval" in perlfunc.
- $_exec
-
$X->$_exec(@ARGS)is equivalent toexec { $X } @ARGS.$X->$_execis equivalent toexec @{$X}if$Xis an array reference andexec $Xotherwise.See "exec" in perlfunc.
- $_exists
-
$X->$_exists($KEY)is equivalent toexists $X->[$KEY]if$Xis an array reference andexists $X->{$KEY}otherwise.See "exists" in perlfunc.
- $_exit
-
$X->$_exitis equivalent toexit $X.See "exit" in perlfunc.
- $_exp
-
$X->$_expis equivalent toexp $X.See "exp" in perlfunc.
- $_fc
-
$X->$_fcis equivalent tofc $X.See "fc" in perlfunc.
- $_getpgrp
-
$X->$_getpgrpis equivalent togetpgrp $X. - $_getpwnam
-
$X->$_getpwnamis equivalent togetpwnam $X. - $_getgrnam
-
$X->$_getgrnamis equivalent togetgrnam $X. - $_gethostbyname
-
$X->$_gethostbynameis equivalent togethostbyname $X. - $_getnetbyname
-
$X->$_getnetbynameis equivalent togetnetbyname $X. - $_getprotobyname
-
$X->$_getprotobynameis equivalent togetprotobyname $X. - $_getpwuid
-
$X->$_getpwuidis equivalent togetpwuid $X. - $_getgrgid
-
$X->$_getgrgidis equivalent togetgrgid $X. - $_getservbyname
-
$X->$_getservbyname($Y)is equivalent togetservbyname $X, $Y. - $_gethostbyaddr
-
$X->$_gethostbyaddr($Y)is equivalent togethostbyaddr $X, $Y. - $_getnetbyaddr
-
$X->$_getnetbyaddr($Y)is equivalent togetnetbyaddr $X, $Y. - $_getprotobynumber
-
$X->$_getprotobynumberis equivalent togetprotobynumber $X. - $_getservbyport
-
$X->$_getservbyport($Y)is equivalent togetservbyport $X, $Y. - $_glob
-
$X->$_globis equivalent to[ glob $X ], i.e. it returns an array reference of results.See "glob" in perlfunc.
- $_gmtime
-
$X->$_gmtimeis equivalent togmtime $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$Fis passed the current element as an argument.See "grep" in perlfunc.
- $_hex
-
$X->$_hexis equivalent tohex $X.See "hex" in perlfunc.
- $_index
-
$X->$_index($NEEDLE)is equivalent toindex $X, $NEEDLE.$X->$_index($NEEDLE, $OFFSET)is equivalent toindex $X, $NEEDLE, $OFFSET.See "index" in perlfunc.
- $_int
-
$X->$_intis equivalent toint $X.See "int" in perlfunc.
- $_join
-
$X->$_join($SEP)is equivalent tojoin $SEP, @{$X}.See "join" in perlfunc.
- $_keys
-
$X->$_keysis equivalent to[ keys @{$X} ]if$Xis an array reference and[ keys %{$X} ]otherwise.See "keys" in perlfunc.
- $_kill
-
$X->$_kill($SIGNAL)is equivalent tokill $SIGNAL, @{$X}if$Xis an array reference andkill $SIGNAL, $Xotherwise.See "kill" in perlfunc.
- $_lc
-
$X->$_lcis equivalent tolc $X.See "lc" in perlfunc.
- $_lcfirst
-
$X->$_lcfirstis equivalent tolcfirst $X. - $_length
-
$X->$_lengthis equivalent tolength $X.See "length" in perlfunc.
- $_link
-
$X->$_link($Y)is equivalent tolink $X, $Y.See "link" in perlfunc.
- $_localtime
-
$X->$_localtimeis equivalent tolocaltime $X. - $_log
-
$X->$_logis equivalent tolog $X.See "log" in perlfunc.
- $_lstat
-
$X->$_lstatis equivalent tolstat $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$Fis passed the current element as an argument.See "map" in perlfunc.
- $_mkdir
-
$X->$_mkdiris equivalent tomkdir $X.See "mkdir" in perlfunc.
- $_oct
-
$X->$_octis equivalent tooct $X.See "oct" in perlfunc.
- $_ord
-
$X->$_ordis equivalent toord $X.See "ord" in perlfunc.
- $_pack
-
$X->$_pack($FORMAT)is equivalent topack $FORMAT, @{$X}if$Xis an array reference andpack $FORMAT, $Xotherwise.See "pack" in perlfunc.
- $_pop
-
$X->$_popis equivalent topop @{$X}.See "pop" in perlfunc.
- $_pos
-
$X->$_posis equivalent topos $X.$X->$_pos($Y)is equivalent topos($X) = $Y.See "pos" in perlfunc.
- $_prototype
-
$X->$_prototypeis equivalent toprototype $X. - $_push
-
$X->$_push(@VALUES)is equivalent topush @{$X}, @VALUES.See "push" in perlfunc.
- $_quotemeta
-
$X->$_quotemetais equivalent toquotemeta $X. - $_rand
-
$X->$_randis equivalent torand $X.See "rand" in perlfunc.
- $_readlink
-
$X->$_readlinkis equivalent toreadlink $X. - $_ref
-
$X->$_refis equivalent toref $X.See "ref" in perlfunc.
- $_rename
-
$X->$_rename($Y)is equivalent torename $X, $Y.See "rename" in perlfunc.
- $_require
-
$X->$_requireis equivalent torequire $X. - $_reverse
-
$X->$_reverseis equivalent to[ reverse @{$X} ]if$Xis an array reference andscalar reverse $Xotherwise. - $_rindex
-
$X->$_rindex($NEEDLE)is equivalent torindex $X, $NEEDLE.$X->$_rindex($NEEDLE, $OFFSET)is equivalent torindex $X, $NEEDLE, $OFFSET.See "rindex" in perlfunc.
- $_rmdir
-
$X->$_rmdiris equivalent tormdir $X.See "rmdir" in perlfunc.
- $_shift
-
$X->$_shiftis equivalent toshift @{$X}.See "shift" in perlfunc.
- $_sin
-
$X->$_sinis equivalent tosin $X.See "sin" in perlfunc.
- $_sleep
-
$X->$_sleepis equivalent tosleep $X.See "sleep" in perlfunc.
- $_sort
-
$X->$_sortis equivalent to[ sort @{$X} ].$X->$_sort($CMP)is equivalent to[ sort { $CMP->($a, $b) } @{$X} ].See "sort" in perlfunc.
- $_splice
-
$X->$_spliceis equivalent tosplice @{$X}.$X->$_splice($OFFSET)is equivalent tosplice @{$X}, $OFFSET.$X->$_splice($OFFSET, $LENGTH)is equivalent tosplice @{$X}, $OFFSET, $LENGTH.$X->$_splice($OFFSET, $LENGTH, @VALUES)is equivalent tosplice @{$X}, $OFFSET, $LENGTH, @VALUES.See "splice" in perlfunc.
- $_split
-
$X->$_splitis 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 tosprintf $FORMAT, @{$X}if$Xis an array reference andsprintf $FORMAT, $Xotherwise.See "sprintf" in perldoc.
- $_sqrt
-
$X->$_sqrtis equivalent tosqrt $X.See "sqrt" in perlfunc.
- $_srand
-
$X->$_srandis equivalent tosrand $X.See "srand" in perlfunc.
- $_stat
-
$X->$_statis equivalent tostat $X.See "stat" in perlfunc.
- $_substr
-
$X->$_substr($OFFSET)is equivalent tosubstr $X, $OFFSET.$X->$_substr($OFFSET, $LENGTH)is equivalent tosubstr $X, $OFFSET, $LENGTH.$X->$_substr($OFFSET, $LENGTH, $REPLACEMENT)is equivalent tosubstr $X, $OFFSET, $LENGTH, $REPLACEMENT.See "substr" in perlfunc.
- $_symlink
-
$X->$_symlink($Y)is equivalent tosymlink $X, $Y. - $_syscall
-
$X->$_syscall(@ARGS)is equivalent tosyscall $X, @ARGS. - $_system
-
$X->$_system(@ARGS)is equivalent tosystem { $X } @ARGS.$X->$_systemis equivalent tosystem @{$X}if$Xis an array reference andsystem $Xotherwise.See "system" in perlfunc.
- $_truncate
-
$X->$_truncate($Y)is equivalent totruncate $X, $Y. - $_uc
-
$X->$_ucis equivalent touc $X.See "uc" in perlfunc.
- $_ucfirst
-
$X->$_ucfirstis equivalent toucfirst $X. - $_umask
-
$X->$_umaskis equivalent toumask $X.See "umask" in perlfunc.
- $_unlink
-
$X->$_unlinkis equivalent tounlink $X.See "unlink" in perlfunc.
- $_unpack
-
$X->$_unpack($FORMAT)is equivalent tounpack $FORMAT, $X.See "unpack" in perlfunc.
- $_unshift
-
$X->$_unshift(@VALUES)is equivalent tounshift @{$X}, @VALUES. - $_utime
-
$X->$_utime($ATIME, $MTIME)is equivalent toutime $ATIME, $MTIME, @{$X}if$Xis an array reference andutime $ATIME, $MTIME, $Xotherwise.See "utime" in perlfunc.
- $_values
-
$X->$_valuesis equivalent to[ values @{$X} ]if$Xis an array reference and[ values %{$X} ]otherwise.See "values" in perlfunc.
- $_vec
-
$X->$_vec($OFFSET, $BITS)is equivalent tovec $X, $OFFSET, $BITS.$X->$_vec($OFFSET, $BITS, $REPLACEMENT) is equivalent to c<< vec($X, $OFFSET, $BITS) = $REPLACEMENT.See "vec" in perlfunc.
- $_waitpid
-
$X->$_waitpidis equivalent towaitpid $X, 0.$X->$_waitpid($FLAGS)is equivalent towaitpid $X, $FLAGS. - $_warn
-
$X->$_warnis equivalent towarn $X.See "warn" in perlfunc.
SEE ALSO
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.