Author image Martin Owens


Template::Direct::Data - Creates a dataset handeler


  use Template::Direct::Data;

  my $data = Template::Direct::Data->new( [ Data ] );

  $datum = $data->getDatum( 'datum_name' );
  $data  = $data->getData( 'datum_name' );

  If you want to add more data you can push another namespace level
  This will force the data checking to check this data first then
  the one before until it reaches the last one.

  $data->pushData( [ More Data ] )
  $data->pushDatum( 'datum_name' )
  $data = $data->popData()


  Control a set of data namespaces which are defined by the top level
  set of names in a hash ref.

  All Data should be in the form { name => value } where value can be
  any hash ref, scalar, or array ref (should work with overridden objects too)

  Based on L<Template::Direct::Compile> (version 2.0) which this replaces


class->new( $data )

  Create a new Data instance.

$data->pushData( $data )

  Add a new data to this data set stack

$data->pushNew( $data )

  Returns a new Data object with $object data plus
  The new data.

$data->pushDatum( $name )

  Find an existing data structure within myself
  And add it as a new namespace; thus bringing it
  into scope.

  Returns 1 if found and 0 if failed to find substruct

$data->pushNewDatum( $name )

  Find an existing data structure within myself and create
  A new object to contain my own data and this new sub scope.

  ( believe it or not this is useful)

$data->popData( )

  Remove the last pushed data from the stack

$data->getDatum( $name, forceString => 1, maxDepth => undef )

  Returns the structure or scalar found in the name.
  The name can be made up of multiple parts:

  name4_45_value is the same as $data{'name4'}[45]{'value'}

  forceString - ensures the result is a string and not an array ref
                or undef values.
  maxDepth    - Maximum number of depths to try before giving up and
                returning nothing, default: infinate.

$data->getArrayDatum( $name )

  Like getDatum but forces output to be an array ref or undef if not valid


  Dumps all data using the current variable scope.

$data->_getSubStructure( $name, $data )

$data->_makeArray( $data )

  Forces the data input to be an array ref:

  Integer  -> Array of indexes [ 0, 1, 2 ... $x ]
  Code     -> Returned from code execution (cont)
  Array    -> Returned Directly
  Hash     -> Returns [ { name => $i, value => $j }, ... ]

$data->_makeHash( $data )

  Forces the data input to be an hash ref:

  Code    -> Returned from code execution (cont)
  Hash    -> Returned Directly
  Other   -> { value => $data }


  Martin Owens - Copyright 2007, AGPL