GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  DATA::UTIL::JA (3)

.ds Aq ’

NAME

Data::Util::JA - XXXXXXXXXXXXXXXXXXXX

CONTENTS

VERSION

This document describes Data::Util version 0.63

SYNOPSIS



        use Data::Util qw(:validate);

        sub foo{
                # they will die if invalid values are supplied
                my $sref = scalar_ref(shift);
                my $aref = array_ref(shift);
                my $href = hash_ref(shift);
                my $cref = code_ref(shift);
                my $gref = glob_ref(shift);
                my $rref = regex_ref(shift);
                my $obj  = instance(shift, Foo);
                # ...
        }

        use Data::Util qw(:check);

        sub bar{
                my $x = shift;
                if(is_scalar_ref $x){
                        # $x is an array reference
                }
                # ...
                elsif(is_instance $x, Foo){
                        # $x is an instance of Foo
                }
                # ...
        }

        # miscelaneous
        use Data::Util qw(:all);

        my $x = anon_scalar();
        $x = anon_scalar($x); # OK

        my $stash = get_stash(Foo);

        install_subroutine(Foo,
                hello  => sub{ "Hello!\n" },
                goodby => sub{ "Goodby!\n" },
        );

        print Foo::hello(); # Hello!

        my($pkg, $name) = get_code_info(\&Foo::hello); # => (Foo, hello)
        my $fqn         = get_code_info(\&Foo::hello); # =>  Foo::Hello
        my $code        = get_code_ref($fqn);          # => \&Foo::hello

        uninstall_subroutine(Foo, qw(hello goodby));

        print neat("Hello!\n"); # => "Hello!\n"
        print neat(3.14);       # => 3.14
        print neat(undef);      # => undef



DESCRIPTION

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

XXXXXXXXXSXPure PerlXXXXXXXXXXXCXXXXXXXX XXXXXSXXXXXXXXXXXXXXPure PerlXXXXXXXXXXXXXX XXXXXXXDATA_UTIL_PUREPERLXXXXXXXXXXXXXXXPure Perl XXXXXXXXXXXXXXXXXXX

XSXXXXXXXXXXXXXXXXXXX Pure PerlXXXXXXXX2XXX10XXXXXXXXXXXX XXXXSXXXXXXXXXXXXXXXXXXXXXXXPure PerlXXXX XXXXXXXXXXXXXXXXXXXXXXX

XXXXXXXXXXXXbenchmark/XXXXXXXXXXXXXXXXXXX

INTERFACE

    Check functions

XXXXXXXX:checkXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXX

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX${}X XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
is_scalar_ref(value) XXXXXXXXXXXXXXXXXXXXXXXXX
is_array_ref(value) XXXXXXXXXXXXXXXXXXXXXXX
is_hash_ref(value) XXXXXXXXXXXXXXXXXXXXXXXXX
is_code_ref(value) XXXXXXXXXXXXXXXXXXXXXXXX
is_glob_ref(value) XXXXXXXXXXXXXXXXXXXXXXXX
is_regex_ref(value) qr//XXXXXXXXXXXXXXXXXXXXXXXXXXX
is_instance(value, class) classXXXXXXXXXXXXXXXXXXXXXX

Scalar::Util::blessed($value) && $value->isa($class)XXXXXXX XXXXXXX

classXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

is_invocant(value) valueXXXXXXXXXXXXXXXXXXXXXXXXXXX
is_value(value) valueXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXX

XXXX(XXXis_string/is_number()/is_integer())XX XXXXXXXXXXXXXXXXXXXXXXXXXX XXXvalueXXXXX/XXX/XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

XXXXXXXXXXXXXXXXXXXXXX

is_string(value) valueXXXXXXXXXXXX XXXXXXXXXXX1XXXXXXXXXXXXXXXXXXXXXXXX

do{ is_value($value) && length($value) > 0 }XXXXXX

XXXXXXXXXXXXXXXXXXXXXX

is_number(value) valueXXXXXXXXXXXXXXXX XXX<B>XXB>XXXXXXXXXXX(XXXXsprintf %g, $valueX XXXXXXXXXXXXXXXXXXX XXPerlXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

XXXXXXXXXXScalar::Util::looks_like_number()XXXXX InfinityXNaNXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX "0 but true"XXXXXXXXXXXXXXXXX

XXXXXXXXXXXXXXXXXXXXXX

is_integer(value) valueXXXXXXXXXXXXXXXXXXXis_number()XXXXXXXX XXXXXXXXXXXXXXXX

XXXXXXXXXXXXXXXXXXXXXX

    Validating functions

XXXXX:validateXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXX

XXXXXXXXXXXXXXXXXXXXXXXXX
scalar_ref(value) XXXXXXXXXXXXXXXXXXXXXXX
array_ref(value) XXXXXXXXXXXXXXXXXXXXX
hash_ref(value) XXXXXXXXXXXXXXXXXXXXXXX
code_ref(value) XXXXXXXXXXXXXXXXXXXXXX
glob_ref(value) XXXXXXXXXXXXXXXXXXXXXX
regex_ref(value) qr//XXXXXXXXXXXXXXXXXXXXXXXXX
instance(value, class) classXXXXXXXXXXXXXXXXXXXX

classXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

invocant(value) valueXXXXXXXXXXXXXXXXXXXXXXXXXXX

valueXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXX"::Foo"X"main::Foo"XXXXX"Foo"XXXXXX

    Micellaneous utilities

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
anon_scalar() undefXXXXXXXXXXXXXXXXXXXXXXXX
anon_scalar(value) valueXXXXXXXXXXXXXXXXXXXXXXXXXXXX

XXXdo{ my $tmp = $value; \$value; }XXXXXXXXXXXX

neat(value) valueXXXXXXXXXXXXXXXXXXXXXX do{ defined($value) ? qq{"$value"} : undef }XXXXXXXX XXXXXXXXXXXXXXXXXXX
get_stash(invocant) invodantXXXXXX <B>stashB>XXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXX

invocantXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXX

invocantXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXX

install_subroutine(package, name => subr [, ...]) XXXXXXsubrXpackageXnameXXXXXXXXXXXXX

do{ no strict refs; *{$package.::.$name} = \&subr; }XXXXXXX XXXXXXXXXXXsubrXXXXXXXXXXXXXXpackageX XXXXXXXXXX&package::nameXXXXXXXX(XXXXPure PerlXXXXXXXXXXXXXXXXXXXXXXXX)X

XXXXXXXXXXXXXXXXXXXXno warnings redefine XXXXXXXXXXXXXXXX



        no warnings redefine;
        install_subrouitne($package, $name => $subr);



packageXnameXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX subrXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXX

XXXXXno strict refsXXXXXXXXXX<B>strictXXXXXXB>XXXXXXXXXXXXXstrictXXXXXXXXXXXXXXXXXXXXXXX



        my $property = ...;
        # ...

        no strict refs;
        # simple read-only accessor
        *{$pkg . :: . $sub_name} = sub{
                my($self) = @_;
                return $self->{$property};
        }



XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXX$selfXXXXXXXXXXXXXXXXXXXXX $self->{$property}XXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXundefXXXXXXXXXX <use strict refs>XXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

XXXXXXstrictXXXXXXXXXXXXXXXXXXXXXXXXX use strictXXXXXXXXXXXXXX



        no strict refs;
        *{$pkg . :: . $sub_name} = sub{
                use strict refs;
                my($self) = @_;
                return $self->{$property};
        }



XXXXinstall_subroutine()XXXXXstrictXXXXXXXXXXXXXXX



        install_subroutine $pkg => (
                $sub_name => sub{
                        my($self) = @_;
                        return $self->{$property};
                },
        );



XXstrictXXXXXXXXXXXX18.10 in PerlXXXXXXXXX XXXXXXX - XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXX

uninstall_subroutine(package, name [=> code], ...) XXXXXXnameXXXXXXpackageXXXXXXXX

undef &subrX&subrXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXuninstall_subroutineXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXX XXXXXnamespace::cleanXconstant::lexicalXXXXXXXXXXXXX

nameXXXXcodeXXXXXXXXXXXX&package::nameXcodeXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX



        uninstall_subroutine($pkg, $name) if \&{$pkg . :: . $name} == $code;
        uninstall_subroutine($pkg, $name => $code);



XXXXXSub::Delete::delete_sub()XXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXX

get_code_info(subr) XXXXXXsubrXXXXXXXXXXXXXXXXXX XXXSub::Identify::get_code_info()XXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXX

subrXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXundefXXXXXX

get_code_ref(package, name) \&package::nameXXXXXXXXXXXXXXX XXXdo{ no strict refs; *{$package . :: . $name}{CODE} } XXXXXXXX\&package::nameXXXXXXXXXX *package::nameXXXXXXXX

XXXXXXX"-create"XXXXXX\&package::nameXXXXXXXX XXXXXXXXXXXXXXXX XXXdo{ no strict refs; \&{$package . :: . $name} }XXXXXX

curry(subr, args and/or placeholders) XXXXXXsubrXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXX

args and/or placeholdersXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxXXX XX\xXX\xXXXXXXXXXXXXXXXXXXXXXXXXX *_XXXXXX

XXXXXXXX$closureX$curriedXXXXXXXXXXXXXXXXXXXX



        my $class = Foo;
        $closure = sub{ is_instance($_[0], $class) };
        $curried = curry \&is_instance, \0, $class;

        $closure = sub{ install_subroutine($class, @_) };
        $curried = curry \&install_subroutine, $class, *_;



XXX*_X\xXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXcurry(\&subr, *_, \1)->(0, 1, 2, 3)XXXXXXXXXX subr(2, 3, 1)XXXXXXXXXXXXXXXXXXXXXXXXXX $_[0](XXX0)XXXXXXXX

XXXXXXXXXXXXXXXXXXXXXXXXXX

XXXXXXXXXXXXXData::Util::CurryXXXXXX

modify_subroutine(subr, modifier_type => [subroutines], ...) XXXXXXsubrXmodifier_typeXXXXXXsubroutinesXXXXX XXXXmodified_subrXXXXXXXX

modifier_typeXXbefore, around, afterXXXXbeforeX subrXXXXXXXXafterXsubrXXXXXXXmodified_subrX XXXXXXXXXXXXXXXXbeforeXafterXXXXXXXXXXXX aroundXsubrXXXXXXXXXXXXXXXXXXXXXXX

XXXXXXXXXXbeforeXaroundXXXXXXXXXXXXXXXXXX (last-defined-first-called)XafterXXXXXXXXXXXXXXXXXXXX(first-defined-first-called)XXXXXXXXXsubroutine_modifier()XXXX XXX

XXXXX



        $modified = modify_subroutine(\&foo, around => [sub{
                my $next = shift;
                do_something();
                goto &{$next}; # continuation
        }]);
        $modified->();

        $modified = modify_subroutine(\&foo,
                before => \@befores,
                around => \@arounds,
                after  => \@afters,
        );
        $modified->();



XSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

XXXXXXXXXXXXXXXXXXXXexample/lib/Method/Modifiers.pm (modify_subroutine()/subroutine_modifier()XXX)XXXXXXX benchmark/methext_bench.plXXXXXXXXXXXXXXXXXXXXXXXXXXXX



        with before modifier: 100% slower
        with after  modifier: 100% slower
        with around modifier: 200% slower



XXXbeforeXafterXSUPER::XXXXXXXXXXXXXXXXXXXXXXXXXX

XXXXXXXXXXMethod Modifiers in Class::MOP::ClassX XXXXXXXXXXXClass::Method::ModifiersXXXXXXXXXX XXXXXXXXXXXXAPIXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXX

subroutine_modifier(modified, modifier_type => subroutines, ...) modify_subroutine()XXXXXmodifiedXXXXXXX

XXXmodifiedXXXXXXXXXXXmodifiedXmodify_subroutine()X XXXXXXXXXXXXXXXXXXXXXXX



        if(subroutine_modifier $subr){
                # $subrXXXXXXXXXXXX
        }



modifiedXmodifier_type(before, around, after) XXXXXXXmodifier_typeXXXXXXXXXXXXXX



        @befores = subroutine_modifier $modified, before;



XXXXXXXXXXXXXXXXXXXXXXmodifiedXmodifier_typeX XXXXXXXXXXX



        subroutine_modifier $modified, before => @befores;



mkopt(input, moniker, require_unique, must_be) inputXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

XXXData::OptList::mkopt()XXXXXXXXXXXXXXmust_beX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

For example:



        $array_ref = mkopt([qw(foo bar), baz => [42]], moniker);
        # $array_ref == [ [foo => undef], [bar => undef], baz => [42] ]



mkopt_hash(input, moniker, must_be) inputXXXXXXXXXXXXXXXXXXXX

XXXData::OptList::mkopt_hash()XXXXXXXXXXXXXXmust_beX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

For example:



        $hash_ref = mkopt([qw(foo bar), baz => [42]], moniker);
        # $hash_ref == { foo => undef, bar => undef, baz => [42] }



    Error handling

XXXXXXXXXXXXXXXXXXXXXData::Util::ErrorXXXXXXXXXXXXXXXXXXXXX



        package Foo;
        use Data::Util::Error sub{ Foo::InvalidArgument->throw(@_) };
        use Data::Util qw(:validate);

        # ...



XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXData::UtilXXXXXXXXXXXXXXXXXXXXXXXXXXX

DISCUSSIONS

What is a X-reference?

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXX3XXXXXXXX
1. ref($x) eq HASH
2. Scalar::Util::reftype($x) eq HASH
3. overload::Method($x, %{})
ref()XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

reftype()XXXXXXXXXXXXX$xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

XXXoverload::MethodXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

XXXXX$xXXXXXXXXXXXXXXXXXXXXXX($x->{$key})XXXXXXXXXXXX$xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

XXXXXXXis_hash_ref()XXXXXXXXXXXXXXXXXXXXXXParams::UtilXXXXXXXXVersion 0.35XXXXXXP::U::_HASHX(1)XXP::U::_HASHLIKEX(2)X(3)XXXXXXXXXXXXXXXXXXXXX(1)XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX(2)XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXis_hash_ref()X(1)X(3)XXXXXXXXXXXXXXXXXXXXXXXXXXXX

XXXXXXis_hash_ref()XXref()Xoverload::Method()XXXXXXXXXXXXXXXXXXis_scalar_ref()Xis_array_ref()Xis_code_ref()Xis_glob_ref()XXXXXX

ENVIRONMENT VARIABLES

    DATA_UTIL_PUREPERL

XXXXXXPure PerlXXXXXXXXXXXXXXX

DEPENDENCIES

Perl 5.8.1 or later.

BUGS AND LIMITATIONS

No bugs have been reported.

Please report any bugs or feature requests to the author.

SEE ALSO

overload.

Scalar::Util.

Class::MOP.

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXSXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Params::Util.

Sub::Install.

Sub::Identify.

Sub::Delete.

Sub::Curry.

Class::Method::Modifiers.

Data::OptList.

AUTHOR

Goro Fuji (gfx) <gfuji(at)cpan.org>

LICENSE AND COPYRIGHT

Copyright (c) 2008-2009, Goro Fuji (gfx) <gfuji(at)cpan.org>. Some rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 DATA::UTIL::JA (3) 2014-03-05

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.