Gantry::Utils::FormMunger - Munges form hashes like the ones bigtop makes.


    use Gantry::Utils::FormMunger;

    my $form = ...; # make a form hash

    my $munger = Gantry::Utils::FormMunger->new( $form );

    # change properties of existing fields:
    $munger->clear_props( 'field_name', qw( name keys to delete) );

    $munger->clear_all_props( 'field_name' );
    # removes all keys except name

        { prop => 'value', ... },
    ); # modifies only the keys you pass

        [ 'field1', 'field2', ... ],
        { prop => 'value', ... },
    ); # like set_props but for all listed fields

        [ 'skip_this_one', 'and_this_one' ],
        { prop => 'value', ... },
    ); # like set_props_for, but negated listed fields are skipped

    $munger->set_props_all( { prop => 'value', ... } );

    # get the field so you can work it yourself:
    my $field = $munger->get_field( 'name' );

    # modify the field list:
    my $deceased = $munger->drop_field( 'name' ); # removes it from the form

    $munger->append_field(  { name => 'name', ... } ); # add at end
    $munger->unshift_field( { name => 'name', ... } ); # add at beginning

    $munger->add_field_after(  'target', { name => 'name', ... } );
    $munger->add_field_before( 'target', { name => 'name', ... } );


This module is designed to simplify work with Gantry form hash data structures. If makes modifications to the fields array in that hash. Usually, bigtop generates that hash. If you are in a standard CRUD situation, the generated form is all you need. But, if you need to share the form in different contexts, it may be necessary to modify it to suit those contexts. That is what this module does.

If you want, you could even use this module to build your entire form hash, but that might be painful. Instead, you usually pass a form hash to its constructor. Usually, you get that hash from a GEN module's form method which was generated by bigtop.

Once you have the object, you can call any of the methods below to modify its fields array. Most of the methods return nothing useful. The exceptions are noted below.

All methods are instance methods unless marked.


new (class method)

Parameters: a form hash. If you don't already have one try:

    my $munger = Gantry::Utils::FormMunger->new( { fields => [] } );

It is better to use one that already has fields.

Returns: a munger object upon which you may call the rest of the methods.


Selectively removes specified properties from one field. This is done by using delete on the fields subhash.

Parameters: name of field to work on, list of properties to remove from its fields hash


Given the name of a field, this method deletes all of its properties except its name.

Parameters: name of field


Given a field name, and a list of properties, sets those properties on that field.



name of field to work on


hash reference of properties to assign on the field


Flag. If true, all keys are deleted prior to application of props. Note that you must supply a name property, or the field will have no name and everyone Will Be Upset.


Like set_props, but works for several named fields at once. This is more efficient than separate calls, since the fields array is only traversed once.

Do not change field names with this method. Use set_props for that. Trying to use this method will leave all fields involved with the same name, confusing everyone including this module.



Array reference, listing fields to work on.


Hash reference of properties to assign on each field.


Like set_props_for, but you list fields to skip, instead of fields to work on. Every field not mentioned is affected. The parameters are the same as for set_props_for.

Note that it is extremely unwise to consider changing field names with this method, since that would make the field names of all fields modified the same.


Like set_props_for, but it works on all fields.

Note that it is extremely unwise to consider changing field names with this method, since that would make all field names the same.



Hash reference of properties to assign on each field.


Returns the subhash for a given field.

Parameters: name of field to return

Returns: subhash for the named field (if there is one)


Deletes a field from the fields array.

Parameters: name of doomed field

Returns: the hash reference for the dearly departed.


Adds a new field at the end of the fields array (so it will appear last on the form).

Parameters: a hash reference for a new field


Just like append_field, except the new field becomes the first field.


Adds a new field to the fields array immediately after a named field. If the named field is not found, the new field goes at the end.



Name of field immediately before new field.


Hash reference of props for new field.


Just like add_field_after, except that the new field goes immediately before the named field. (If the name is not found, the new field still goes at the end.)


Phil Crow, <<gt>


Copyright (C) 2007 Phil Crow

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.