Form::Processor::Field::HtmlArea - Input HTML in a textarea


Form-Processor documentation Contained in the Form-Processor distribution.

Index


Code Index:

NAME

Top

Form::Processor::Field::HtmlArea - Input HTML in a textarea

SYNOPSIS

Top

See Form::Processor

DESCRIPTION

Top

Field validates using HTML::Tidy. A simple Tidy configuration file is created and written to disk each time the field is validated.

Widget

Fields can be given a widget type that is used as a hint for the code that renders the field.

This field's widget type is: "textarea".

Subclass

Fields may inherit from other fields. This field inherits from: "Textarea".

DEPENDENCIES

Top

HTML::Tidy File::Temp

AUTHORS

Top

Bill Moseley

COPYRIGHT

Top

SUPPORT / WARRANTY

Top

Form::Processor is free software and is provided WITHOUT WARRANTY OF ANY KIND. Users are expected to review software for fitness and usability.


Form-Processor documentation Contained in the Form-Processor distribution.

package Form::Processor::Field::HtmlArea;
use strict;
use warnings;
use base 'Form::Processor::Field::TextArea';
use HTML::Tidy;
use File::Temp;
our $VERSION = '0.03';

my $tidy;

sub init_widget { 'textarea' }

sub validate {
    my $field = shift;

    return unless $field->SUPER::validate;

    $tidy ||= $field->tidy;
    $tidy->clear_messages;


    # parse doesn't pass the config file in HTML::Tidy.
    $tidy->clean( $field->input );

    my $ok = 1;

    for ( $tidy->messages ) {
        $field->add_error( $_->as_string );
        $ok = 0;
    }

    return $ok;
}


# Parses config file.  Do it once.

my $tidy_config;
sub tidy {
    my $field = shift;
    $tidy_config ||= $field->init_tidy;
    my $t = HTML::Tidy->new( { config_file => $tidy_config } );


    $t->ignore( text => qr/DOCTYPE/ );
    $t->ignore( text => qr/missing 'title'/ );
    # $t->ignore( type => TIDY_WARNING );

    return $t;
}


sub init_tidy {

    my $tidy_conf = <<EOF;
char-encoding: utf8
input-encoding: utf8
output-xhtml: yes
logical-emphasis: yes
quiet: yes
show-body-only: yes
wrap: 45
EOF



    my $tidy_file = File::Temp->new( UNLINK => 1 );
    print $tidy_file $tidy_conf;
    close $tidy_file;

    return $tidy_file;


}



1;