The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Data::Structure::Util - Change nature of data within a structure

SYNOPSIS

  use Data::Structure::Util qw(has_utf8 utf8_off utf8_on unbless get_blessed has_circular_ref);
  
  $data = {
            key1 => 'hello',
            key2 => bless({}, 'Foo'),
          };
  $data->{key3} = \$data;

  utf8_off($data) if has_utf8($data);

  $objs = get_blessed($data);
  unbless($data) if @$objs;

  die "Found a circular reference!" if has_circular_ref($data);

DESCRIPTION

Data::Structure::Util is a toolbox to manipulate data inside a data structure. It can transform to utf8 any string within a data structure. I can attempts to transform any utf8 string back to default encoding either. It can remove the blessing on any reference. It can collect all the objects or detect if there is a circular reference.

It is written in C for decent speed.

FUNCTIONS

has_utf8($ref)

Returns true if there is a utf8 (as noted by perl) string within the data structure referenced by $ref

utf8_off($ref)

Attempts to decode from utf8 any string within the data structure referenced by $ref

utf8_on($ref)

Encode to utf8 any string within the data structure referenced by $ref

unbless($ref)

Remove the blessing from any object found wihtin the date structure referenced by $ref

get_blessed($ref)

Returns an array ref of all objects within the data structure. The data structure is parsed deep first, so the top most objects should be the last elements of the array.

has_circular_ref($ref)

If a circular reference is detected, it returns the reference to an element composing the circuit. Returns false if no circular reference is detected. Example:

  if ($circular_ref = has_circular_ref($ref)) {
    warn "Got a circular reference, you can use 'weaken' from Scalar::Util module to break it";
  }

SEE ALSO

Scalar::Util, Devel::Leak, Devel::LeakTrace

THANKS TO

James Duncan and Arthur Bergman who provided me with help and a name for this module

AUTHOR

Pierre Denis <pdenis@fotango.com>

COPYRIGHT

Copyright 2003 Fotango - All Rights Reserved.

This module is released under the same license as Perl itself.