++ed by:
9 non-PAUSE users
Author image Eric Strom


List::Gen::Builtins - perl builtin functions with partial + lazy application


this module implements most of the perl functions with fn() from List::Gen::Lazy. you can import functions from this module as follows:


builtin's with prototypes have the same prototype when exported from this module.

to export the builtins in ucfirst:

    use List::Gen::Builtins;  # ucfirst is default

    my $int = Int my $float;

    $float = 4.333;

    say $int; # 4

or to export prefixed with '_' :

    use List::Gen::Builtins ':_';

    my $int = _int my $float;

or to export prefixed with 'lazy_' :

    use List::Gen::Builtins ':lazy';

    my $int = lazy_int my $float;

to export the builtins as like named userspace functions:

    use List::Gen::Builtins ':userspace';

    my $int = &int(my $float);

note that as always, when a user function is called with & , prototypes are disabled, this means that you must call functions like &shift as:

    my $x = &shift(\@array);  # must use parens and manually take the reference

the implemented functions are:

    abs accept alarm atan2 bind binmode bless caller chdir chmod chomp chop
    chown chr chroot close closedir connect cos crypt dbmclose dbmopen default
    defined die do endgrent endhostent endnetent endprotoent endpwent
    endservent eof eval exec exit exp fcntl fileno flock fork formline getc
    getgrent getgrgid getgrnam gethostbyaddr gethostbyname gethostent getlogin
    getnetbyaddr getnetbyname getnetent getpeername getpgrp getppid getpriority
    getprotobyname getprotobynumber getprotoent getpwent getpwnam getpwuid
    getservbyname getservbyport getservent getsockname getsockopt glob gmtime
    goto hex index int ioctl join keys kill lc lcfirst length link listen
    localtime lock log lstat mkdir msgctl msgget msgrcv msgsnd oct open opendir
    ord pack pipe pop pos print printf prototype push quotemeta rand read
    readdir readline readlink readpipe recv ref rename require reset reverse
    rewinddir rindex rmdir say scalar seek seekdir select semctl semget semop
    send setgrent sethostent setnetent setpgrp setpriority setprotoent setpwent
    setservent setsockopt shift shmctl shmget shmread shmwrite shutdown sin
    sleep socket socketpair splice split sprintf sqrt srand stat study substr
    symlink syscall sysopen sysread sysseek system syswrite tell telldir tied
    time times truncate uc ucfirst umask undef unlink unpack unshift untie utime
    values vec wait waitpid wantarray warn when write

just because they have been implemented, that says nothing about their usefulness as a lazy function.



wrap is used to automatically wrap the builtin functions in a fn(...) function that calls the builtin with the arguments passed in.

    *lazy_open = wrap 'open',
        styles => {
            1   => ['\@'],
            2   => ['\@', '$',],
            3   => ['\@', '$', '$'],
            '@' => ['\@', '$', '$', '@']
        proto => '\@;$$@';
        arity => 1,
        returns => 1;

all of the options are optional, in fact, with a proper prototype, wrap will determine everything itself:

    *lazy_open = wrap 'open';  # same as with the options above

wrap does not install anything, it returns the lazy coderef.


Eric Strom, <asg at cpan.org>


this module has barely been tested, ymmv

several functions are not available in 5.13+ and a warning will be generated. to silence this:

    BEGIN {$List::Gen::Lazy::Builtins::WARN = 0}  # before calling 'use'
    use List::Gen::Lazy::Builtins;

report any bugs / feature requests to bug-list-gen at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=List-Gen.

comments / feedback / patches are also welcome.


copyright 2009-2011 Eric Strom.

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.