Index: trunk/lib/Text/FormBuilder.pm
===================================================================
--- trunk/lib/Text/FormBuilder.pm	(revision 26)
+++ trunk/lib/Text/FormBuilder.pm	(revision 28)
@@ -6,5 +6,5 @@
 use vars qw($VERSION);
 
-$VERSION = '0.06_01';
+$VERSION = '0.06_02';
 
 use Carp;
@@ -12,5 +12,5 @@
 use CGI::FormBuilder;
 
-# the default options passed to CGI::FormBuilder->new
+# the static default options passed to CGI::FormBuilder->new
 my %DEFAULT_OPTIONS = (
     method => 'GET',
@@ -77,5 +77,5 @@
     
     # substitute in custom pattern definitions for field validation
-    if (my %patterns = %{ $self->{form_spec}{patterns} }) {
+    if (my %patterns = %{ $self->{form_spec}{patterns} || {} }) {
         foreach (@{ $self->{form_spec}{fields} }) {
             if ($$_{validate} and exists $patterns{$$_{validate}}) {
@@ -85,12 +85,7 @@
     }
     
-##     # so we don't get all fields required
-##     foreach (@{ $self->{form_spec}{fields} }) {
-##         delete $$_{validate} unless $$_{validate};
-##     }
-
     # expand groups
-    my %groups = %{ $self->{form_spec}{groups} };
-    foreach (grep { $$_[0] eq 'group' } @{ $self->{form_spec}{lines} }) {
+    my %groups = %{ $self->{form_spec}{groups} || {} };
+    foreach (grep { $$_[0] eq 'group' } @{ $self->{form_spec}{lines} || [] }) {
         $$_[1]{group} =~ s/^\%//;       # strip leading % from group var name
         
@@ -107,5 +102,5 @@
     
     $self->{form_spec}{fields} = [];
-    for my $line (@{ $self->{form_spec}{lines} }) {
+    for my $line (@{ $self->{form_spec}{lines} || [] }) {
         if ($$line[0] eq 'group') {
             push @{ $self->{form_spec}{fields} }, $_ foreach @{ $$line[1]{group} };
@@ -117,5 +112,5 @@
     
     # substitute in list names
-    my %lists = %{ $self->{form_spec}{lists} };
+    my %lists = %{ $self->{form_spec}{lists} || {} };
     foreach (@{ $self->{form_spec}{fields} }) {
         next unless $$_{list};
@@ -169,5 +164,4 @@
             data => {
                 lines       => $self->{form_spec}{lines},
-                headings    => $self->{form_spec}{headings},
                 author      => $self->{form_spec}{author},
                 description => $self->{form_spec}{description},
@@ -215,12 +209,4 @@
     # don't dump $VARn names
     $Data::Dumper::Terse = 1;
-    
-    my $title       = $self->{form_spec}{title} || '';
-    my $author      = $self->{form_spec}{author} || '';
-    my $description = $self->{form_spec}{description} || '';
-    
-    my $headings    = Data::Dumper->Dump([$self->{form_spec}{headings}],['headings']);
-    my $lines       = Data::Dumper->Dump([$self->{form_spec}{lines}],['lines']);
-    my $fields      = Data::Dumper->Dump([ [ map { $$_{name} } @{ $self->{form_spec}{fields} } ] ],['fields']);
     
     my %options = (
@@ -238,5 +224,4 @@
             data => {
                 lines       => $self->{form_spec}{lines},
-                headings    => $self->{form_spec}{headings},
                 author      => $self->{form_spec}{author},
                 description => $self->{form_spec}{description},
@@ -338,7 +323,4 @@
         $OUT .= (grep { $$_{invalid} } @group_fields) ? qq[  <tr class="invalid">\n] : qq[  <tr>\n];
         
-        #TODO: validated but not required fields
-        # in a form spec: //EMAIL?
-        
         $OUT .= '    <th class="label">';
         $OUT .= (grep { $$_{required} } @group_fields) ? qq[<strong class="required">$$line[1]{label}:</strong>] : "$$line[1]{label}:";
@@ -740,10 +722,11 @@
 =head1 TODO
 
-DWIM for single valued checkboxes (e.g. C<moreinfo|Send me more info:checkbox>)
-
 Use the custom message file format for messages in the built in template
 
 C<!section> directive to split up the table into multiple tables, each
 with their own id and (optional) heading
+
+Use HTML::Template instead of Text::Template for the built in template
+(since CGI::FormBuilder users may be more likely to already have HTML::Template)
 
 Better examples in the docs (maybe a standalone or two as well)
Index: trunk/lib/Text/FormBuilder/grammar
===================================================================
--- trunk/lib/Text/FormBuilder/grammar	(revision 26)
+++ trunk/lib/Text/FormBuilder/grammar	(revision 28)
@@ -8,8 +8,6 @@
 	%lists,
 	%patterns,
-	@fields,
 	@group,        # current group
 	%groups,       # stored groups of fields
-	@headings,
 	$type,
 	@options,
@@ -23,5 +21,5 @@
 }
 
-form_spec: (list_def | description_def | group_def | line)(s) 
+form_spec: (list_def | description_def | group_def | line)(s)
     {
 	$return = {
@@ -29,10 +27,8 @@
 	    author   => $author,
 	    description => $description,
-	    lists    => \%lists    || {}, 
-	    patterns => \%patterns || {}, 
-	    headings => \@headings || [],
-	    fields   => \@fields   || [],
-	    lines    => \@lines    || [],
-	    groups   => \%groups   || {},
+	    lists    => \%lists,
+	    patterns => \%patterns,
+	    lines    => \@lines,
+	    groups   => \%groups,
 	}
     }
@@ -71,9 +67,14 @@
 
 title: '!title' /.*/
-    { warn "[Text::Formbuilder] Title redefined at input text line $thisline\n" if defined $title;
-    $title = $item[2] }
+    {
+	warn "[Text::Formbuilder] Title redefined at input text line $thisline\n" if defined $title;
+	$title = $item[2];
+    }
 
 author: '!author' /.*/
-    { $author = $item[2] }
+    {
+	warn "[Text::Formbuilder] Author redefined at input text line $thisline\n" if defined $author;
+	$author = $item[2];
+    }
 
 pattern_def: '!pattern' var_name pattern
@@ -82,14 +83,9 @@
 pattern: /.*/
 
-heading: '!head' /.*/
-    {
-	warn "[Text::FormBuilder] Header before field " . scalar(@fields) . " redefined at input text line $thisline\n" if defined $headings[@fields];
-	$headings[@fields] = $item[2];
-	push @lines, [ 'head', $item[2] ];
-    }
+heading: '!head' /.*/    { push @lines, [ 'head', $item[2] ] }
 
 group_field: '!field' group_name name label(?)
-    { #warn "[$thisline] $item{group_name}\n"; 
-    push @lines, [ 'group', { name => $item{name}, label => $item{'label(?)'}[0], group => $item{group_name} } ];
+    { 
+	push @lines, [ 'group', { name => $item{name}, label => $item{'label(?)'}[0], group => $item{group_name} } ];
     }
 
@@ -115,13 +111,10 @@
 	$$field{size} = $size if defined $size;
 	
-	#warn "[$thisline] field $item{name}; context $context\n";   
+	#warn "[$thisline] field $item{name}; context $context\n";
 	if ($context eq 'group') {
 	    push @group, $field;
 	} else {
-	    push @fields, $field;
 	    push @lines, [ 'field', $field ];
 	}
-	
-	#warn "field $item{name} is required" if $required;
 	
 	$type = undef;
