Changeset 52 in text-formbuilder for trunk


Ignore:
Timestamp:
01/03/05 13:41:53 (20 years ago)
Author:
peichman
Message:

failure to load Perl::Tidy is no longer fatal
create_form tries to emit tidy code
expanded documentation for bin/fb.pl

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Changes

    r50 r52  
    11Release history for Text::FormBuilder. 
    22 
     30.08 
     4    * failure to load Perl::Tidy is no longer fatal 
     5    * create_form tries to emit tidy code 
     6     
    370.07 - 16 Dec 2004 
    48    * added a create_form exported method to "do the right 
  • trunk/bin/fb.pl

    r1 r52  
    1111my $src_file = shift; 
    1212 
    13 Text::FormBuilder->parse($src_file)->build(%fb_options)->write($outfile); 
     13create_form($src_file, \%fb_options, $outfile); 
     14#Text::FormBuilder->parse($src_file)->build(%fb_options)->write($outfile); 
    1415 
    1516=head1 NAME 
     
    2324    $ fb my_form.txt -o my_form.html -D action=/cgi-bin/my-script.pl 
    2425 
     26=head1 DESCRIPTION 
     27 
     28Parses a formspec file from the command line and creates an output 
     29file. The sort of output file depends on the value given to the C<-o> 
     30option. If it ends in F<.pm>, a standalone module is created. If it 
     31ends in F<.pl> or F<.cgi>, a skeleton CGI script is created. Any other 
     32value, will be taken as the name of an HTML file to write. Finally, if 
     33not C<-o> option is given then the HTML will be written to STDOUT. 
     34 
    2535=head1 OPTIONS 
    2636 
    2737=over 
    2838 
    29 =item -D <parameter>=<value> 
     39=item C<< -D <parameter>=<value> >> 
    3040 
    3141Define options that are passed to the CGI::FormBuilder object. For example, 
     
    3545    $ fb ... -D action=/cgi-bin/some_script.pl 
    3646 
    37 =item -o <output file> 
     47=item C<< -o <output file> >> 
     48 
     49Where to write output, and what form to write it in. See C<create_form> in  
     50L<Text::FormBuilder> for a more detailed explanation. 
     51 
     52    # write a standalone module 
     53    $ fb myform -o MyForm.pm 
     54     
     55    # write a CGI script 
     56    $ fb myform -o form.cgi 
     57 
     58=back 
     59 
     60=head1 AUTHOR 
     61 
     62Peter Eichman, C<< <peichman@cpan.org> >> 
     63 
     64=head1 COPYRIGHT AND LICENSE 
     65 
     66Copyright E<copy>2004 by Peter Eichman. 
     67 
     68This program is free software; you can redistribute it and/or 
     69modify it under the same terms as Perl itself. 
     70 
     71=cut 
  • trunk/lib/Text/FormBuilder.pm

    r50 r52  
    77use vars qw($VERSION @EXPORT); 
    88 
    9 $VERSION = '0.07'; 
     9$VERSION = '0.08_01'; 
    1010@EXPORT = qw(create_form); 
    1111 
     
    6464            # write webpage, script, or module 
    6565            if ($destination =~ $MODULE_EXTS) { 
    66                 $parser->write_module($destination); 
     66                $parser->write_module($destination, 1); 
    6767            } elsif ($destination =~ $SCRIPT_EXTS) { 
    68                 $parser->write_script($destination); 
     68                $parser->write_script($destination, 1); 
    6969            } else { 
    7070                $parser->write($destination); 
     
    439439    croak '[Text::FormBuilder::write_module] Expecting a package name' unless $package; 
    440440     
     441    # remove a trailing .pm 
     442    $package =~ s/\.pm$//; 
     443##     warn  "[Text::FromBuilder::write_module] Removed extra '.pm' from package name\n" if $package =~ s/\.pm$//; 
     444     
    441445    my $form_code = $self->_form_code; 
    442446     
     
    499503        # clean up the generated code, if asked 
    500504        eval 'use Perl::Tidy'; 
    501         die "Can't tidy the code: $@" if $@; 
    502         Perl::Tidy::perltidy(source => \$source_code, destination => $outfile, argv => $TIDY_OPTIONS); 
     505        unless ($@) { 
     506            Perl::Tidy::perltidy(source => \$source_code, destination => $outfile, argv => $TIDY_OPTIONS); 
     507        } else { 
     508            carp "Can't tidy the code: $@" if $@; 
     509            # fallback to just writing it as-is 
     510            open OUT, "> $outfile" or die $!; 
     511            print OUT $source_code; 
     512            close OUT; 
     513        } 
    503514    } else { 
    504515        # otherwise, just print as is 
     
    11941205=head1 TODO 
    11951206 
     1207Improve the commmand line tools 
     1208 
    11961209Allow renaming of the submit button; allow renaming and inclusion of a  
    11971210reset button 
     1211 
     1212Allow groups to be used in normal field lines something like this: 
     1213 
     1214    !group DATE { 
     1215        month 
     1216        day 
     1217        year 
     1218    } 
     1219     
     1220    dob|Your birthday:DATE 
     1221 
     1222Pieces that wouldn't make sense in a group field: size, row/col, options, 
     1223validate. These should cause C<build> to emit a warning before ignoring them. 
     1224 
     1225Make the generated modules into subclasses of CGI::FormBuilder 
    11981226 
    11991227Allow for custom wrappers around the C<form_template> 
Note: See TracChangeset for help on using the changeset viewer.