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

NAME

Gapp::Form::Context - Form context object

SYNOPSIS

  # use an object

  $o = Foo::Character->new( fname => 'Mickey', lname => 'Mouse' );

  $cx = Gapp::Form::Context->new(

    reader_prefix => 'get_',

    writer_prefix => 'set_'

  );

  $cx->add( 'character', $o );

  $cx->lookup( 'character.fname' ); # returns 'Mickey'

  # use a hash-ref

  $data = { foo => 'bar' };
  
  $cx->add( data => $data,

      accessor => sub {

        my ( $data, $attr, $value ) = @_;

        @_ == 2 ? $data{$attr} : $data{$attr} = $value;

      }

  );
  
  $cx->lookup( 'data.foo' ); # returns 'Bar'

DESCRIPTION

The context is used to sync data between objects/data structures and forms.

OBJECT HIERARCHY

Gapp::Form::Context

PROVIDED ATTRIBUTES

accessor
is rw
isa CodeRef|Undef
default Undef

If accessor is defined, it will be used as the default accessor for nodes in the context. The accessor is used to update and retrieve data from the data sctructure. If no accessor is set, reader and writer methods will be used.

reader_prefix
is rw
isa Str|Undef
default Undef

If reader_prefix is defined, it will be used as the default reader_prefix for nodes in the context. When doing a lookup, the reader_prefix is appended to beginning of the attribute name to form the reader method. This method will then be called on the data structure to retrieve the value. If an accessor has been defined, that will be used instead.

writer_prefix
is rw
isa Str|Undef
default Undef

If writer_prefix is defined, it will be used as the default writer_prefix for nodes in the context. When doing a modify, the writer_prefix is appended to beginning of the attribute name to form the writer method. This method will then be called on the data structure to store the value. If an accessor has been defined, that will be used instead.

PROVIDED METHODS

add $node_name, $data_structure|CodeRef, @opts

Add a node to the context. All nodes must have name. The $data_structure is the Object or other data to work on. If any options are specified, they will over-ride those set by the context. The avaialble options are accessor, reader_prefix, writer_prefix.

lookup $path

Retrieves a value from the context. $path is a string in the format of "node_name.attribute".

get_node $node_name

Retrieves a Gapp::Form::Context::Node from the context with the given $node_name.

modify $path, $new_value

Sets a value in the context. $path is a string in the format of "nodename.attribute".

set_node $node_name, $node

Add Gapp::Form::Context::Node to the context with the given $name.

update $stash

Updates the values in the context based on values in the $stash. $stash is a Gapp::Form::Stash object.

AUTHORS

Jeffrey Ray Hallock <jeffrey.hallock at gmail dot com>

COPYRIGHT & LICENSE

    Copyright (c) 2011-2012 Jeffrey Ray Hallock.

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