Workflow::Validator man page on Fedora

Man page or keyword search:  
man Server   31170 pages
apropos Keyword Search (all sections)
Output format
Fedora logo
[printable version]

Workflow::Validator(3)User Contributed Perl DocumentatioWorkflow::Validator(3)

NAME
       Workflow::Validator - Ensure data are valid

VERSION
       This documentation describes version 1.05 of this package

SYNOPSIS
	# First declare the validator...
	<validator name="DateValidator"
		   class="MyApp::Validator::Date">
	  <param name="date_format" value="%Y-%m-%d %h:%m"/>
	</validator>

	# Then associate the validator with runtime data from the context...
	<action name="MyAction">
	   <validator name="DateValidator">
	      <arg>$due_date</arg>
	   </validator>
	</action>

	# TODO: You can also inintialize and instantiate in one step if you
	# don't need to centralize or reuse (does this work?)

	<action name="MyAction">
	   <validator class="MyApp::Validator::Date">
	      <param name="date_format" value="%Y-%m-%d %h:%m"/>
	      <arg>$due_date</arg>
	   </validator>
	</action>

	# Then implement the logic

	package MyApp::Validator::Date;

	use strict;
	use base qw( Workflow::Validator );
	use DateTime::Format::Strptime;
	use Workflow::Exception qw( configuration_error );

	__PACKAGE__->mk_accessors( 'formatter' );

	sub _init {
	    my ( $self, $params ) = @_;
	    unless ( $params->{date_format} ) {
		configuration_error
		    "You must define a value for 'date_format' in ",
		    "declaration of validator ", $self->name;
	    }
	    if ( ref $params->{date_format} ) {
		configuration_error
		    "The value for 'date_format' must be a simple scalar in ",
		    "declaration of validator ", $self->name;
	    }
	    my $formatter = DateTime::Format::Strptime->new(
				     pattern => $params->{date_format},
				     on_error => 'undef' );
	    $self->formatter( $formatter );
	}

	sub validate {
	    my ( $self, $wf, $date_string ) = @_;
	    my $fmt = $self->formatter;
	    my $date_object = $fmt->parse_datetime( $date_string );
	    unless ( $date_object ) {
		validation_error
		    "Date '$date_string' does not match pattern '", $fmt->pattern, "' ",
		    "due to error '", $fmt->errstr, "'";
	    }
	}

DESCRIPTION
       Validators specified by 'validator_name' are looked up in the
       Workflow::Factory which reads a separate configuration and generates
       validators. (Generally all validators should be declared, but it is not
       required.)

       Validators are objects with a single public method, 'validate()' that
       take as arguments a workflow object and a list of parameters. The
       parameters are filled in by the workflow engine according to the
       instantiation declaration in the Action.

       The idea behind a validator is that it validates data but does not care
       where it comes from.

SUBCLASSING
   Strategy
   Methods
       init( \%params )

       Called when the validator is first initialized. If you do not have
       sufficient information in "\%params" you should throw an exception.

       _init

       This is a dummy method, please see "init".

       validate( $workflow, $data )

       Determine whether your $data is true or false. If necessary you can get
       the application context information from the $workflow object.

COPYRIGHT
       Copyright (c) 2003-2004 Chris Winters. All rights reserved.

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

AUTHORS
       Chris Winters <chris@cwinters.com>

perl v5.14.1			  2011-07-21		Workflow::Validator(3)
[top]

List of man pages available for Fedora

Copyright (c) for man pages and the logo by the respective OS vendor.

For those who want to learn more, the polarhome community provides shell access and support.

[legal] [privacy] [GNU] [policy] [cookies] [netiquette] [sponsors] [FAQ]
Tweet
Polarhome, production since 1999.
Member of Polarhome portal.
Based on Fawad Halim's script.
....................................................................
Vote for polarhome
Free Shell Accounts :: the biggest list on the net