HTML::Shakan::Fields - fields


HTML-Shakan documentation Contained in the HTML-Shakan distribution.

Index


Code Index:

NAME

Top

HTML::Shakan::Fields - fields

DESCRIPTION

Top

This module exports some functions, that generates a instance of HTML::Field::*.

If you want to know the details, please look the source :)

FUNCTIONS

Top

TextField(name => 'foo')

create a instance of HTML::Shakan::Input.

This is same as HTML::Shakan::Input->new(name => 'foo', type => 'text', @_);

EmailField(name => 'email')

TextField() + EMAIL_LOOSE constraint.

URLField(name => 'url')

TextField() + HTTP_URL constraint

UIntField(name => 'i')

TextField() + UINT constraint

IntField(name => 'i')

TextField() + INT constraint

PasswordField(name => 'pw')

define <input type="password" /> field

FileField(name => 'file')

define <input type="fiel" /> field

ImageField(name => 'image')

FileField + FILE_MIME=image/* constraint

ChoiceField(name => 'interest', choices => [qw/moose mouse exporter/])

selector field.

DateField(name => 'birthdate')

date input field.

Duplication('mail' => EmailField(), EmailField())

both field contains same value?

AUTHORS

Top

Tokuhiro Matsuno(tokuhirom)

SEE ALSO

Top

HTML::Shakan

use Params::Validate ':all';


HTML-Shakan documentation Contained in the HTML-Shakan distribution.

package HTML::Shakan::Fields;
use strict;
use warnings;
use parent 'Exporter';
use Carp ();

our @EXPORT = qw(
    TextField
    EmailField
    URLField
    UIntField
    IntField

    PasswordField

    FileField
    ImageField

    ChoiceField

    DateField

    Duplication
);

# DateTimeField
# ImageField
# TimeField

sub _input {
    HTML::Shakan::Field::Input->new( @_ );
}

sub TextField {
    _input(type => 'text', @_);
}

sub EmailField {
    TextField(@_)->add_constraint('EMAIL_LOOSE');
}

sub URLField {
    TextField(@_)->add_constraint('HTTP_URL');
}

sub UIntField {
    TextField(@_)->add_constraint('UINT');
}

sub IntField {
    TextField(@_)->add_constraint('INT');
}

sub PasswordField {
    _input(type => 'password', @_);
}

sub FileField {
    HTML::Shakan::Field::File->new(@_);
}

sub ImageField {
    FileField(@_)->add_constraint(['FILE_MIME' => qr{image/.+}]);
}

sub ChoiceField {
    HTML::Shakan::Field::Choice->new( @_ );
}

sub DateField {
    HTML::Shakan::Field::Date->new( @_ );
}

sub Duplication {
    my ($name, $f1, $f2) = @_;
    Carp::croak('missing args. Usage: Duplication(name, field1, field2)') unless @_ == 3;
    $f1->add_complex_constraint(
        +{ $name => [ $f1->name(), $f2->name() ] } => [ 'DUPLICATION' ]
    );
    return ($f1, $f2);
}

1;
__END__