| 1 | |||
| 2 | ########################################################################### | ||
| 3 | # Copyright (c) Nate Wiger http://nateware.com. All Rights Reserved. | ||
| 4 | # Please visit http://formbuilder.org for tutorials, support, and examples. | ||
| 5 | ########################################################################### | ||
| 6 | |||
| 7 | package CGI::FormBuilder::Source; | ||
| 8 | |||
| 9 | =head1 NAME | ||
| 10 | |||
| 11 | CGI::FormBuilder::Source - Source adapters for FormBuilder | ||
| 12 | |||
| 13 | =head1 SYNOPSIS | ||
| 14 | |||
| 15 | # Define a source adapter | ||
| 16 | |||
| 17 | package CGI::FormBuilder::Source::Whatever; | ||
| 18 | |||
| 19 | sub new { | ||
| 20 | my $self = shift; | ||
| 21 | my $class = ref($self) || $self; | ||
| 22 | my %opt = @_; | ||
| 23 | return bless \%opt, $class; | ||
| 24 | } | ||
| 25 | |||
| 26 | sub parse { | ||
| 27 | my $self = shift; | ||
| 28 | my $file = shift || $self->{source}; | ||
| 29 | |||
| 30 | # open the file and parse it, or whatever | ||
| 31 | my %formopt; | ||
| 32 | open(F, "<$file") || die "Can't read $file: $!"; | ||
| 33 | while (<F>) { | ||
| 34 | # ... do stuff to the line ... | ||
| 35 | $formopt{$fb_option} = $fb_value; | ||
| 36 | } | ||
| 37 | |||
| 38 | # return hash of $form options | ||
| 39 | return wantarray ? %formopt : \%formopt; | ||
| 40 | } | ||
| 41 | |||
| 42 | =cut | ||
| 43 | |||
| 44 | use strict; | ||
| 45 | use warnings; | ||
| 46 | no warnings 'uninitialized'; | ||
| 47 | |||
| 48 | our $VERSION = '3.10'; | ||
| 49 | warn __PACKAGE__, " is not a real module, please read the docs\n"; | ||
| 50 | 1; | ||
| 51 | __END__ |