Gapp::Form::Context - Form context object
# 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'
The context is used to sync data between objects/data structures and forms.
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.
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.
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.
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
.
Retrieves a value from the context. $path
is a string in the format of "node_name.attribute".
Retrieves a Gapp::Form::Context::Node from the context with the given $node_name
.
Sets a value in the context. $path
is a string in the format of "nodename.attribute".
Add Gapp::Form::Context::Node to the context with the given $name
.
Updates the values in the context based on values in the $stash
. $stash
is a Gapp::Form::Stash object.
Jeffrey Ray Hallock <jeffrey.hallock at gmail dot com>
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.