Changeset 88 in text-formbuilder for trunk


Ignore:
Timestamp:
06/29/05 16:46:56 (19 years ago)
Author:
peichman
Message:

BUGFIX: stopped crosstalk of data from one object to another (references were getting shared in the parser grammar code)

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Changes

    r87 r88  
    22 
    330.12 
     4    * BUGFIX: stopped crosstalk of data from one object to another 
    45    * added !fb directive to set FB constructor parameters directly; 
    56      uses YAML to hold strucutred data 
  • trunk/lib/Text/FormBuilder.pm

    r87 r88  
    198198                push @{ $self->{form_spec}{fields} }, { %{$_} } foreach @{ $$line[1]{group} }; 
    199199            } elsif ($$line[0] eq 'field') { 
     200                #die $$line[1] unless ref $$line[1]; 
    200201                push @{ $self->{form_spec}{fields} }, { %{$$line[1]} }; 
    201202            } 
     
    13491350=head2 Language/Parser 
    13501351 
    1351 Make sure that multiple runs of the parser don't share data. 
    1352  
    13531352Pieces that wouldn't make sense in a group field: size, row/col, options, 
    13541353validate. These should cause C<build> to emit a warning before ignoring them. 
     
    13701369 
    13711370=head1 BUGS 
    1372  
    1373 Creating two $parsers in the same script causes the second one to get the data 
    1374 from the first one. 
    13751371 
    13761372Placing C<fields> in a C<!fb> directive does not behave as expected (i.e. they 
  • trunk/lib/Text/FormBuilder/grammar

    r87 r88  
    3737 
    3838form_spec: 
    39     {  
    40         %formspec = ();  # clear the old formspec data 
     39    { 
     40        # clear out old data, so we don't end up with old data in new objects 
     41        @lines    = (); 
     42        @sections = (); 
     43        %formspec = (); 
    4144    } 
    4245    (list_def | description_def | group_def | note | fb_params | unknown_block_directive | line)(s) 
     
    5255        } 
    5356         
     57        # make copies instead of taking references, again so we 
     58        # don't end up with connections between objects 
    5459        $return = { 
    5560            fb_params   => $formspec{fb_params}, 
     
    5762            author      => $formspec{author}, 
    5863            description => $formspec{description}, 
    59             lists       => \%lists, 
    60             patterns    => \%patterns, 
    61             subs        => \%subs, 
    62             groups      => \%groups, 
    63             sections    => \@sections, 
    64             ( @submit ?  
    65                 (submit => @submit == 1 ? $submit[0] : \@submit) : 
    66                 () 
    67             ), 
     64            lists       => { %lists }, 
     65            patterns    => { %patterns }, 
     66            subs        => { %subs }, 
     67            groups      => { %groups }, 
     68            sections    => [ @sections ], 
     69            ( @submit ? (submit => @submit == 1 ? $submit[0] : [ @submit ]) : () ), 
    6870            reset       => $formspec{reset}, 
    6971        } 
     
    233235        @options = (); 
    234236         
     237        #warn "$$field{name}: $field"; 
     238         
    235239        $field; 
    236240    } 
  • trunk/t/Text-FormBuilder.t

    r87 r88  
    44######################### 
    55 
    6 # change 'tests => 1' to 'tests => last_test_to_print'; 
    7  
    8 use Test::More tests => 10; 
     6use Test::More qw(no_plan); #tests => 11; 
    97BEGIN { use_ok('Text::FormBuilder'); }; 
    10  
    11 ######################### 
    12  
    13 # Insert your test code below, the Test::More module is use()ed here so read 
    14 # its man page ( perldoc Test::More ) for help writing this test script. 
    158 
    169my $p = Text::FormBuilder->new; 
     
    3932is(keys %{ $form->fields }, 3, 'correct number of fields'); 
    4033 
    41 my $p2 = Text::FormBuilder->parse_array([qw(code title semester instructor)]); 
    42 is(keys %{ $p2->form->fields }, 4, 'correct number of fields from parse_array'); 
    43 #$p2->write; 
     34# create some additional parsers, to make sure we aren't sharing data 
     35my $p2 = Text::FormBuilder->parse_text($simple); 
     36is(keys %{ $p2->form->fields }, 3, 'correct number of fields from parse_text'); 
     37 
     38my $p3 = Text::FormBuilder->parse_array(qw(code title semester instructor)); 
     39is(keys %{ $p3->form->fields }, 4, 'correct number of fields from parse_array'); 
Note: See TracChangeset for help on using the changeset viewer.