Provided by: libdata-util-perl_0.62-1build1_amd64
NAME
Data::Util::JA - XXXXXXXXXXXXXXXXXXXX
VERSION
This document describes Data::Util version 0.62
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 XXXXXXX"DATA_UTIL_PUREPERL"XXXXXXXXXXXXXXXPure Perl XXXXXXXXXXXXXXXXXXX XSXXXXXXXXXXXXXXXXXXX Pure PerlXXXXXXXX2XXX10XXXXXXXXXXXX XXXXSXXXXXXXXXXXXXXXXXXXXXXXPure PerlXXXX XXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXbenchmark/XXXXXXXXXXXXXXXXXXX
INTERFACE
Check functions XXXXXXXX":check"XXXXXXXXXXXXXXXXXXXXXXXXX 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(XXX"is_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 XXXXXXXXXXXXXXXX(XXXX"sprintf '%g', $value"X XXXXXXXXXXXXXXXXXXX XXPerlXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXX"Scalar::Util::looks_like_number()"XXXXX "Infinity"X"NaN"XXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX "0 but true"XXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXX is_integer(value) valueXXXXXXXXXXXXXXXXXXX"is_number()"XXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXX Validating functions XXXXX":validate"XXXXXXXXXXXXXXXXXXXXXXXX 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() "undef"XXXXXXXXXXXXXXXXXXXXXXXX anon_scalar(value) valueXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXX"do{ my $tmp = $value; \$value; }"XXXXXXXXXXXX neat(value) valueXXXXXXXXXXXXXXXXXXXXXX "do{ defined($value) ? qq{"$value"} : 'undef' }"XXXXXXXX XXXXXXXXXXXXXXXXXXX get_stash(invocant) invodantXXXXXX stashXXXXXXXXXXXXXXXXX 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 XXXXXXXXXXXXXXXXXXXX"no warnings 'redefine'" XXXXXXXXXXXXXXXX no warnings 'redefine'; install_subrouitne($package, $name => $subr); packageXnameXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX subrXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXX XXXXX"no strict 'refs'"XXXXXXXXXXstrictXXXXXXXXXXXXXXXXXXXstrictXXXXXXXXXXXXXXXXXXXXXXX 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 XXXXXXXXXXX"undef"XXXXXXXXXX "<use strict 'refs'">XXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXstrictXXXXXXXXXXXXXXXXXXXXXXXXX "use strict"XXXXXXXXXXXXXX no strict 'refs'; *{$pkg . '::' . $sub_name} = sub{ use strict 'refs'; my($self) = @_; return $self->{$property}; } XXXX"install_subroutine()"XXXXX"strict"XXXXXXXXXXXXXXX install_subroutine $pkg => ( $sub_name => sub{ my($self) = @_; return $self->{$property}; }, ); XXstrictXXXXXXXXXXXX"18.10" in "PerlXXXXXXXXX" XXXXXXX - XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXX uninstall_subroutine(package, name [=> code], ...) XXXXXXnameXXXXXXpackageXXXXXXXX "undef &subr"X&subrXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXX"uninstall_subroutine"XXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXX XXXXX"namespace::clean"X"constant::lexical"XXXXXXXXXXXXX nameXXXXcodeXXXXXXXXXXXX&package::nameXcodeXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX uninstall_subroutine($pkg, $name) if \&{$pkg . '::' . $name} == $code; uninstall_subroutine($pkg, $name => $code); XXXXX"Sub::Delete::delete_sub()"XXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXX get_code_info(subr) XXXXXXsubrXXXXXXXXXXXXXXXXXX XXX"Sub::Identify::get_code_info()"XXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXX subrXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXX"undef"XXXXXX get_code_ref(package, name) \&package::nameXXXXXXXXXXXXXXX XXX"do{ no strict 'refs'; *{$package . '::' . $name}{CODE} }" XXXXXXXX\&package::nameXXXXXXXXXX *package::nameXXXXXXXX XXXXXXX"-create"XXXXXX\&package::nameXXXXXXXX XXXXXXXXXXXXXXXX XXX"do{ no strict 'refs'; \&{$package . '::' . $name} }"XXXXXX curry(subr, args and/or placeholders) XXXXXXsubrXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXX args and/or placeholdersXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxXXX XX"\x"XX"\x"XXXXXXXXXXXXXXXXXXXXXXXXX *_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"\x"XXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXX"curry(\&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_typeXX"before", "around", "after"XXXX"before"X subrXXXXXXXX"after"XsubrXXXXXXXmodified_subrX XXXXXXXXXXXXXXXX"before"X"after"XXXXXXXXXXXX "around"XsubrXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXX"before"X"around"XXXXXXXXXXXXXXXXXX (last-defined-first-called)X"after"XXXXXXXXXXXXXXXXXXXX(first-defined-first-called)XXXXXXXXX"subroutine_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 XXX"before"X"after"X"SUPER::"XXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXX"Method Modifiers" in Class::MOP::ClassX XXXXXXXXXXXClass::Method::ModifiersXXXXXXXXXX XXXXXXXXXXXXAPIXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXX subroutine_modifier(modified, modifier_type => subroutines, ...) "modify_subroutine()"XXXXXmodifiedXXXXXXX XXXmodifiedXXXXXXXXXXXmodifiedX"modify_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 XXX"Data::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 XXX"Data::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 XXXXXXXXXXXXXXXXXXXXX"Data::Util::Error"XXXXXXXXXXXXXXXXXXXXX package Foo; use Data::Util::Error sub{ Foo::InvalidArgument->throw(@_) }; use Data::Util qw(:validate); # ... XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"Data::Util"XXXXXXXXXXXXXXXXXXXXXXXXXXX
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 XXX"overload::Method"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXX$xXXXXXXXXXXXXXXXXXXXXXX("$x->{$key}")XXXXXXXXXXXX$xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXX"is_hash_ref()"XXXXXXXXXXXXXXXXXXXXXX"Params::Util"XXXXXXXXVersion 0.35XXXXXX"P::U::_HASH"X(1)XX"P::U::_HASHLIKE"X(2)X(3)XXXXXXXXXXXXXXXXXXXXX(1)XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX(2)XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"is_hash_ref()"X(1)X(3)XXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXX"is_hash_ref()"XX"ref()"X"overload::Method()"XXXXXXXXXXXXXXXXXX"is_scalar_ref()"X"is_array_ref()"X"is_code_ref()"X"is_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.