NAME

Data::Util - A selection of utilities for data and data types

VERSION

This document describes Data::Util version 0.64

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 $rx   = rx(shift); # regular expression
            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('Foo', 'hello');  # => \&Foo::hello

    uninstall_subroutine('Foo', qw(hello goodby));

# simple format for errro messages (not the same as Data::Dumper)
    print neat("Hello!\n"); # => "Hello!\n"
    print neat(3.14);       # => 3.14
    print neat(undef);      # => undef

DESCRIPTION

This module provides utility functions for data and data types, including functions for subroutines and symbol table hashes (stashes).

The implementation of this module is both Pure Perl and XS, so if you have a C compiler, all the functions this module provides are really faster.

There are many benchmarks in the DIST-DIR/benchmark/ directory.

INTERFACE

Check functions

Check functions are introduced by the :check import tag, which check the argument type and return a bool.

These functions also checks overloading magic, e.g. ${} for a SCALAR reference.

Validating functions

Validating functions are introduced by the :validate tag which check the argument and returns the first argument. These are like the :check functions but dies if the argument type is invalid.

These functions also checks overloading magic, e.g. ${} for a SCALAR reference.

Miscellaneous utilities

There are some other utility functions you can import from this module.

ENVIRONMENT VARIABLES

DATA_UTIL_PUREPERL

If true, Data::Util uses the Pure Perl implementation.

DEPENDENCIES

Perl 5.8.1 or later.

If you have a C compiler, you can use the XS backend, but the Pure Perl backend is also available if you have no C compilers.

BUGS AND LIMITATIONS

No bugs have been reported.

Please report any bugs or feature requests to the author.

SEE ALSO

Scalar::Util.

overload.

Params::Util.

Sub::Install.

Sub::Identify.

Sub::Delete.

Sub::Curry.

Class::MOP.

Class::Method::Modifiers.

Data::OptList.

Mouse

AUTHOR

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

LICENSE AND COPYRIGHT

Copyright (c) 2008-2010, Goro Fuji <gfuji(at)cpan.org>. All rights reserved.

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