NAME

Top Close Open

Template::TT3::Type::Hash - hash virtual object

SYNOPSIS

Top Close Open
# TODO

DESCRIPTION

Top Close Open

Note: we use the term 'list' interchangeably with 'array' here. Technically speaking we mean "reference to an array" when we say "reference to a list" and so on, but we don't worry too much about the distinction in TT land.

Note: all these methods can be called as subroutines, passing a reference to a hash array as the first argument.

    my $hash = Template::TT3::Type::Hash->new( a => 10 );
    $hash->keys();  # [ a ]

    my $data = { b => 20 };
    Template::TT3::Type::Hash::keys($data);   # [ b ]

    # lookup method from hash object, pass raw hash data as argument
    $hash->can('keys')->($data);            # [ b ]

METHODS

Top Close Open

new()

Top Close Open

Constructor method to create a new hash array. A reference to a Hash object, hash array or a list of named parameters can be passed as argument(s) to define the contents of the Hash object. If a Hash object is passed as an argument then it is first cloned. If a reference to a hash array is passed then it is blessed into a Hash object without being copied. If a list of named parameters is passed then they are merged into a new hash array which is then blessed and returned as a Hash object.

clone()

Top Close Open

Creates a new Hash object as a copy of the current one. A reference to a Hash object, hash array or a list of named parameters can be passed as argument(s) to define any additional data items to be added to the cloned Hash object.

copy()

Top Close Open

Returns a reference to an unblessed hash array containing a copy of the current Hash object and any additional items passed by reference to another Hash object, hash array or as a list of named parameters.

ref()

Top Close Open

Returns the string 'HASH', equivalent to Perl's ref() function.

type()

Top Close Open

Returns the string 'Hash' to indicate the TT data type.

hash()

Top Close Open

Returns the Hash object unchanged, effectively a null operation.

list()

Top Close Open

Returns a reference to a list containing the Hash object as a single item.

text($keyval_delim,$items_delim)

Top Close Open

Returns a text representation of the hash array. One or two optional arguments can be provided. The first is used to define a delimiter to be used between key/value pairs. The default value is => . The second argument can be used to provide an alternate delimiter to be used between successive pairs of items. The default value is , .

keys()

Top Close Open

Returns a reference to a list containing the keys of the hash array, as per Perl's keys() function.

values()

Top Close Open

Returns a reference to a list containing the values of the hash array, as per Perl's values() function.

each()

Top Close Open

Returns a reference to a list containing the interleaved keys and values of the hash array.

kvlist()

Top Close Open

Returns a reference to a list containing references to lists, each of which contains a key and value from the hash array.

kvhash()

Top Close Open

Returns a reference to a list containing references to hash arrays, each of which contains a key and value from the hash array.

item($key)

Top Close Open

TODO

exists($key)

Top Close Open

TODO

defined($key)

Top Close Open

TODO

sort()

Top Close Open

Sorts the values in the hash array alphabetically and returns a list of keys corresponding to that order. If you want a list of keys in sorted order, then simply call the keys() method and sort the values returned.

nsort()

Top Close Open

As per sort(), but returns the keys corresponding to the values sorted numerically.

delete($key)

Top Close Open

Delete an item from the hash.

import($hash)

Top Close Open

Import the contents of another hash.

AUTHOR

Top Close Open

Andy Wardley http://wardley.org

COPYRIGHT

Top Close Open

Copyright (C) 1996-2009 Andy Wardley. All Rights Reserved.

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


http://tt3.template-toolkit.org/docs/Template/TT3/Type/Hash.pm last modified 2009-12-23 14:54:17