NAME

CGI::Application::CheckRM - Checks run modes using Data::FormValidator

VERSION 1.21

Included in CGI-Application-Plus 1.21 distribution.

The latest versions changes are reported in the Changes file in this distribution.

The distribution includes:

  • CGI::Application::Plus

    CGI::Application rewriting with several pluses

  • CGI::Application::Magic

    Template based framework for CGI applications

  • CGI::Application::CheckRM

    Checks run modes using Data::FormValidator

INSTALLATION

Prerequisites
    Perl version >= 5.6.1
    OOTools      >= 1.52
CPAN
    perl -MCPAN -e 'install CGI::Application::Plus'

If you want to install also all the prerequisites to use CGI::Application::Magic), all in one easy step:

    perl -MCPAN -e 'install Bundle::Application::Magic'
Standard installation

From the directory where this file is located, type:

    perl Makefile.PL
    make
    make test
    make install

SYNOPSIS

    use base 'CGI::Application::CheckRM';
    
    $s->checkRM('_form_profile')
      || return $s->switch_to('myOtherRunMode');
    
    my $ERRORS = $s->dfv_resuts->msgs

DESCRIPTION

This module integrates the Data::FormValidator capability with CGI::Application::Plus or with CGI::Application::Magic.

INTEGRATION

The integration with CGI::Application::Magic is very powerful.

You need just to pass the profile to the checkRM() method and put the labels in the template: no other configuration needed on your side: the error labels in any template will be auto-magically substituted with the error string when needed.

Note: The hash reference returned by the msgs() method will be internally passed as a lookup location to the Template::Magic object.

CGI::Application::Magic Example 1

In your WebAppMagic.pm

    use base 'CGI::Application::Magic';
    use base 'CGI::Application::CheckRM';
    
    sub RM_myRunMode
    {
      my $s = shift ;
      $s->checkRM('_form_profile')
        || return $s->switch_to('myOtherRunMode');
      ...
    }
    
    # the RM_myOtherRunMode method is optional
    
    sub _form_profile
    {
       return { required => 'email',
                msgs     => { any_errors => 'some_errors',
                              prefix     => 'err_',
                             },
              };
    }

Somewhere in the 'myOtherRunMode.html' template (or in any other template) all the label prefixed with 'err_' will be substitute with the relative error if present (with the _form_profile in the example it happens just with 'err_email'):

    <!--{err_email}-->

CGI::Application::Magic Example 2

In your WebAppMagic.pm

    use base 'CGI::Application::Magic';
    use base 'CGI::Application::CheckRM';
    
    sub RM_myRunMode
    {
      my $s = shift ;
      $s->checkRM('_form_profile')
        || return $s->switch_to('myOtherRunMode');
      ...
    }
    
    # the RM_myOtherRunMode method is optional
    
    sub _form_profile
    {
       return { required => 'email',
                msgs     => { any_errors => 'some_errors',
                              prefix     => 'err_',
                             },
              };
    }
    
    package WebAppMagic::Lookups;
    
    sub MISSING
    {
      my $s = shift ;
      my $missing
      if ( $s->dfv_resuts->has_missing )
      {
        foreach my $f ( $s->dfv_resuts->missing )
        {
           $missing .= $f, " is missing\n";
        }
      }
      $missing
    }

Somewhere in the 'myOtherRunMode.html' template (or in any other template) all the 'MISSING' labels will be substitute with the relative error if present:

    <!--{MISSING}-->

CGI::Application::Plus Example

You can use this module with CGI::Application::Plus, but you will have to handle the errors in the runmethod:

In your WebAppPlus.pm

    use base 'CGI::Application::Plus';
    use base 'CGI::Application::CheckRM';
    
    sub RM_myRunMode
    {
      my $s = shift ;
      $s->checkRM('_form_profile')
        || return $s->switch_to('myOtherRunMode');
      ...
    }
    
    sub RM_myOtherRunMode
    {
      my $s  = shift;
      my $ERRORS = $s->dfv_resuts->msgs ; # classical way
      
      # or do something else with the result object
      
      if ( $s->dfv_resuts->has_missing )
      {
        foreach my $f ( $s->dfv_resuts->missing )
        {
           $ERRORS .= $f, " is missing\n";
        }
      }
      ... do_something_useful ...
    }
    
    sub _form_profile
    {
       return { required => 'email',
                msgs     => { any_errors => 'some_errors',
                              prefix     => 'err_',
                             },
              };
    }

METHODS

checkRM ( dfv_profile )

Use this method to check the query parameters with the dfv_profile. It returns 1 on success and 0 on failure. If there are some missing or unvalid fields it set also the dfv_results property to the Data::FormValidator::Results object.

PROPERTY and GROUP ACCESSORS

This module adds a couple of properties to the standard CGI::Application::Plus properties.

dfv_defaults

This group accessor handles the Data::FormValidator constructor arguments that are used in the creation of the internal Data::FormValidator object.

dfv_results

This property allows you to access the Data::FormValidator::Results object set by the checkRM() method only if there are some missing or invalid fields.

SUPPORT and FEEDBACK

If you need support or if you want just to send me some feedback or request, please use this link: http://perl.4pro.net/?CGI::Application::CheckRM.

AUTHOR and COPYRIGHT

© 2004 by Domizio Demichelis.

All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as perl itself.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 276:

Non-ASCII character seen before =encoding in '©'. Assuming CP1252