Changeset 7 in text-formbuilder


Ignore:
Timestamp:
10/06/04 13:44:15 (20 years ago)
Author:
peter
Message:

removed dependecies on YAML and Parse::RecDescent
renamed _dump to dump; now only tries to load YAML if it is called; non-fatal error if YAML cannot be loaded
modified bin/fb-cgi.pl
expanded docs

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Makefile.PL

    r4 r7  
    88    EXE_FILES         => [ 'bin/fb.pl' ], 
    99    PREREQ_PM         => {  
    10                             Parse::RecDescent => 1.94, 
    1110                            CGI::FormBuilder => 2.12, 
    12                             YAML => 0.35, 
    1311                         }, # e.g., Module::Name => 1.1 
    1412    ($] >= 5.005 ?     ## Add these new keywords supported since 5.005 
  • trunk/bin/fb-cgi.pl

    r1 r7  
    1212my $form = $parser->parse($src_file)->build(method => 'POST', params => $q)->form; 
    1313 
    14 if ($form->submitted && $form->validate) { 
    15     # TODO: 
     14if (1 or $form->submitted && $form->validate) { 
     15 
    1616    # call storage function 
     17 
    1718    my $plugin = 'DumpParams'; 
     19     
    1820    eval "use $plugin;"; 
    19      
    20     if ($plugin->process($q)) { 
     21    die "Can't use $plugin; $@" if $@; 
     22    die "Plugin $plugin doesn't know how to process" unless $plugin->can('process'); 
     23 
     24    # plugin process method should return a true value 
     25    if ($plugin->process($q, $form)) { 
    2126        # show thank you page 
    22         #print $q->header('text/plain'); 
    23         #print "Thank you for your input!\n" 
    2427    } else { 
    2528        # there was an error processing the results 
     29        die "There was an error processing the submission: " . $plugin->error; 
    2630    } 
    2731     
  • trunk/lib/Text/FormBuilder.pm

    r1 r7  
    44use warnings; 
    55 
    6 our $VERSION = '0.01'; 
     6our $VERSION = '0.02'; 
    77 
    88use Text::FormBuilder::Parser; 
    99use CGI::FormBuilder; 
    10 use YAML; 
    1110 
    1211sub new { 
     
    153152} 
    154153 
    155 sub _dump { print YAML::Dump(shift->{form_spec}); } 
     154sub dump {  
     155    eval "use YAML;"; 
     156    unless ($@) { 
     157        print YAML::Dump(shift->{form_spec}); 
     158    } else { 
     159        warn "Can't dump form spec structure: $@"; 
     160    } 
     161} 
    156162 
    157163 
     
    170176    # returns a new CGI::FormBuilder object with the fields 
    171177    # from the input form spec 
    172     my $form = $parser->build_form; 
     178    my $form = $parser->form; 
    173179 
    174180=head1 DESCRIPTION 
     
    178184=head2 parse 
    179185 
     186    $parser->parse($src_file); 
     187     
     188    # or as a class method 
     189    my $parser = Txt::FormBuilder->parse($src_file); 
     190 
     191=head2 parse_text 
     192 
    180193=head2 build 
    181194 
     195Options passed to build are passed on verbatim to the L<CGI::FormBuilder> 
     196constructor. Any options given here override the defaults that this module 
     197uses. 
     198 
     199=head2 form 
     200 
     201    my $form = $parser->form; 
     202 
     203Returns the L<CGI::FormBuilder> object. 
     204 
    182205=head2 write 
    183206 
     207    $parser->write($out_file); 
     208    # or just print to STDOUT 
     209    $parser->write; 
     210 
     211Calls C<render> on the FormBuilder form, and either writes the resulting HTML 
     212to a file, or to STDOUT if no filename is given. 
     213 
     214=head2 dump 
     215 
     216Uses L<YAML> to print out a human-readable representaiton of the parsed 
     217form spec. 
     218 
    184219=head1 LANGUAGE 
    185220 
    186     name[size]|descriptive label[hint]:type=default{option1(display string),option2(display string),...}//validate 
     221    name[size]|descriptive label[hint]:type=default{option1[display string],option2[display string],...}//validate 
    187222     
    188223    !title ... 
     
    190225    !pattern name /regular expression/ 
    191226    !list name { 
    192         option1(display string), 
    193         option2(display string), 
     227        option1[display string], 
     228        option2[display string], 
    194229        ... 
    195230    } 
     
    204239 
    205240=item C<!title> 
     241 
     242=item C<!author> 
    206243 
    207244=back 
     
    220257Any line beginning with a C<#> is considered a comment. 
    221258 
     259=head1 TODO 
     260 
     261=head2 Langauge 
     262 
     263Directive for a descriptive or explanatory paragraph about the form 
     264 
     265Subsection headers? 
     266 
    222267=head1 SEE ALSO 
    223268 
Note: See TracChangeset for help on using the changeset viewer.