On 24/09/2007, Zbigniew Lukasiak <[EMAIL PROTECTED]> wrote: > On 9/24/07, Carl Franks <[EMAIL PROTECTED]> wrote: > > On 24/09/2007, Zbigniew Lukasiak <[EMAIL PROTECTED]> wrote: > > > This thread reminds me of my other idea - how about letting the form > > > to load the config from a string instead of a file? This would let > > > you create some more self-containing tests. > > > > Can you give an example of what you're thinking of? > > Sure. When I write tests I need to create two files - the test itself > and the config file. For example - this is my test: > > my $form = HTML::FormFu->new( { stash => { schema => $schema } } ); > $form->load_config_file('t/var/config.yml'); > my $by_pkey = $form->get_element( { name => 'by_pkey' } ); > my $options = $by_pkey->_options; > is ( scalar @$options, 3, 'Number of options' ); > > It would be simpler if I could provide the config directly in the test: > my $form = HTML::FormFu->new( { stash => { schema => $schema } } ); > my $config = " > --- > elements: > - type: MySelect > name: by_pkey > resultset: User > search_attr: > order_by: > - id > - type: MySelect > name: name > resultset: User > presentation: name > search_attr: > order_by: > - id > - type: MySelect > name: where > resultset: User > presentation: name > search_attr: > where: > id: 3 > order_by: > - id > " > > $form->load_config( $config ); > > Then - when writing about some bug I could just send one self > containing test case - and you could just run it and see the results.
There's 2 ways already of doing something similar: use HTML::FormFu; use YAML::Syck qw( Load ); my $form = HTML::FormFu->new; $form->populate( Load( do { local $/; <DATA> } ) ); print $form; __DATA__ --- elements: - name: foo - name: bar ... or ... use HTML::FormFu; use YAML::Syck qw( Load ); my $form = HTML::FormFu->new; $form->populate( Load( <<END ) ); --- elements: - name: foo - name: bar END print $form; Because load_config_file() uses Config::Any in the background, so as to allow freedom of choice of config format, I wouldn't really want to provide a yaml-specific method, if it's only real benefit is in test files. Carl _______________________________________________ HTML-FormFu mailing list HTML-FormFu@lists.scsys.co.uk http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu