Index: trunk/lib/Text/FormBuilder.pm
===================================================================
--- trunk/lib/Text/FormBuilder.pm	(revision 52)
+++ trunk/lib/Text/FormBuilder.pm	(revision 53)
@@ -4,8 +4,8 @@
 use warnings;
 
-use base qw(Exporter);
+use base qw(Exporter Class::ParseText::Base);
 use vars qw($VERSION @EXPORT);
 
-$VERSION = '0.08_01';
+$VERSION = '0.08';
 @EXPORT = qw(create_form);
 
@@ -59,6 +59,6 @@
     if ($destination) {
         if (ref $destination) {
-            croak "[Text::FormBuilder::create_form] Don't know what to do with a ref for $destination";
-            #TODO: what do ref dests mean?
+            croak '[' . (caller(0))[3] . "] Don't know what to do with a ref for $destination";
+            #TODO: what DO ref dests mean?
         } else {
             # write webpage, script, or module
@@ -75,66 +75,11 @@
     }
 }
-    
-
-sub new {
-    my $invocant = shift;
-    my $class = ref $invocant || $invocant;
-    my $self = {
-        parser => Text::FormBuilder::Parser->new,
-    };
-    return bless $self, $class;
-}
-
-sub parse {
-    my ($self, $source) = @_;
-    if (my $type = ref $source) {
-        if ($type eq 'SCALAR') {
-            $self->parse_text($$source);
-        } elsif ($type eq 'ARRAY') {
-            $self->parse_array(@$source);
-        } else {
-            croak "[Text::FormBuilder::parse] Unknown ref type $type passed as source";
-        }
-    } else {
-        $self->parse_file($source);
-    }
-}
-
-sub parse_array {
-    my ($self, @lines) = @_;
-    # so it can be called as a class method
-    $self = $self->new unless ref $self;    
-    $self->parse_text(join("\n", @lines));    
-    return $self;
-}
-
-sub parse_file {
-    my ($self, $filename) = @_;
-    
-    # so it can be called as a class method
-    $self = $self->new unless ref $self;
-    
-    local $/ = undef;
-    open SRC, "< $filename" or croak "[Text::FormBuilder::parse_file] Can't open $filename: $!" and return;
-    my $src = <SRC>;
-    close SRC;
-    
-    return $self->parse_text($src);
-}
-
-sub parse_text {
-    my ($self, $src) = @_;
-    
-    # so it can be called as a class method
-    $self = $self->new unless ref $self;
-    
-    # append a newline so that it can be called on a single field easily
-    $src .= "\n";
-    
-    $self->{form_spec} = $self->{parser}->form_spec($src);
-    
-    # mark structures as not built (newly parsed text)
-    $self->{built} = 0;
-    
+
+# subclass of Class::ParseText::Base
+sub init {
+    my $self = shift;
+    $self->{parser}         = Text::FormBuilder::Parser->new;
+    $self->{start_rule}     = 'form_spec';
+    $self->{ensure_newline} = 1;
     return $self;
 }
@@ -180,5 +125,5 @@
                 close MESSAGES;
             } else {
-                carp "[Text::FormBuilder] Could not read messages file $options{messages}: $!";
+                carp '[' . (caller(0))[3] . "] Could not read messages file $options{messages}: $!";
             }
         }
@@ -187,4 +132,5 @@
     }
     
+    # character set
     my $charset = $options{charset};
     
@@ -240,5 +186,5 @@
             # for now, we just warn that it doesn't work
             } elsif (exists $subs{$$_{validate}}) {
-                warn "[Text::FormBuilder] validate coderefs don't work yet";
+                warn '[' . (caller(0))[3] . "] validate coderefs don't work yet";
                 delete $$_{validate};
 ##                 $$_{validate} = $subs{$$_{validate}};
@@ -437,5 +383,5 @@
     my ($self, $package, $use_tidy) = @_;
 
-    croak '[Text::FormBuilder::write_module] Expecting a package name' unless $package;
+    croak '[' . (caller(0))[3] . '] Expecting a package name' unless $package;
     
     # remove a trailing .pm
@@ -471,5 +417,5 @@
     my ($self, $script_name, $use_tidy) = @_;
 
-    croak '[Text::FormBuilder::write_script] Expecting a script name' unless $script_name;
+    croak '[' . (caller(0))[3] . '] Expecting a script name' unless $script_name;
     
     my $form_code = $self->_form_code;
@@ -506,5 +452,5 @@
             Perl::Tidy::perltidy(source => \$source_code, destination => $outfile, argv => $TIDY_OPTIONS);
         } else {
-            carp "Can't tidy the code: $@" if $@;
+            carp '[' . (caller(0))[3] . "] Can't tidy the code: $@" if $@;
             # fallback to just writing it as-is
             open OUT, "> $outfile" or die $!;
@@ -650,5 +596,5 @@
         print YAML::Dump(shift->{form_spec});
     } else {
-        warn "Can't dump form spec structure: $@";
+        warn '[' . (caller(0))[3] . "] Can't dump form spec structure using YAML: $@";
     }
 }
@@ -1265,5 +1211,5 @@
 =head1 COPYRIGHT AND LICENSE
 
-Copyright E<copy>2004 by Peter Eichman.
+Copyright E<copy>2004-2005 by Peter Eichman.
 
 This program is free software; you can redistribute it and/or
