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.
accessor
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.
reader_prefix
lookup
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.
writer_prefix
modify
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.
$data_structure
Object
Retrieves a value from the context. $path is a string in the format of "node_name.attribute".
$path
Retrieves a Gapp::Form::Context::Node from the context with the given $node_name.
$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.
$name
Updates the values in the context based on values in the $stash. $stash is a Gapp::Form::Stash object.
$stash
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.
To install Gapp, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Gapp
CPAN shell
perl -MCPAN -e shell install Gapp
For more information on module installation, please visit the detailed CPAN module installation guide.