CGI::FormBuilder::Source::Perl - read FormBuilder config from Perl syntax files


CGI-FormBuilder-Source-Perl documentation Contained in the CGI-FormBuilder-Source-Perl distribution.

Index


Code Index:

NAME

Top

CGI::FormBuilder::Source::Perl - read FormBuilder config from Perl syntax files

SYNOPSIS

Top

    my $form = CGI::FormBuilder->new(
        source => {
            type   => 'Perl',
            source => '/path/to/form_config.pl',
        }
    );

DESCRIPTION

Top

This module allows you to specify the config for a CGI::FormBuilder object using Perl syntax. The contents of the config file will be evaled and the hash ref returned will be used as the config for the object.

SEE ALSO

Top

CGI::FormBuilder, CGI::FormBuilder::Source::File,

AUTHOR

Top

Copyright (c) 2008 Edmund von der Burg <evdb@ecclestoad.co.uk>. All Rights Reserved.

Based on the module CGI::FormBuilder::Source

This module is free software; you may copy this under the terms of the GNU General Public License, or the Artistic License, copies of which should have accompanied your Perl kit.


CGI-FormBuilder-Source-Perl documentation Contained in the CGI-FormBuilder-Source-Perl distribution.
package CGI::FormBuilder::Source::Perl;

use strict;
use warnings;

our $VERSION = '0.01';

use File::Slurp;

sub new {
    my $self  = shift;
    my $class = ref($self) || $self;
    my %opt   = @_;
    return bless \%opt, $class;
}

sub parse {
    my $self = shift;
    my $file = shift || $self->{source};

    my $content = read_file($file);
    my $config  = eval $content;
    die "ERROR in C:FB:Source::Perl config file '$file': $@" if $@;

    # FIXME - add caching and smarter checking

    return wantarray ? %$config : $config;
}

1;