[html-formfu] HTML::FormFu::Element::DBIC::Select for review

Zbigniew Lukasiak zzbbyy at gmail.com
Tue Sep 25 12:23:40 GMT 2007


On 9/24/07, Mario Minati <mario.minati at googlemail.com> wrote:
>
> I don't think setup is the right place to do this work.
> When you look at what is happening when creating an element with perl not YAML
> like in 04basic.t:
> The element is created with a call to 'element' (defined in ObjectUtil, around
> line 623).
> This functions calls '_single_element' (defined in ObjectUtil, around line
> 721).
> This function calls '_require_element' (defined in ObjectUtil, around line
> 74).
> And here the 'setup' method of the element is invoked.
> It works fine as long you create your element with all data in place like with
> YAML, but it will fail when doing the chained creation like in the mentioned
> testfile 04basic.t.
>

Hmm - thanks - now I think I am getting what is the relation between
the yaml config and object creators in FormFu.

How about adding just one function:

sub options_from {
    my ( $self, $args )  = @_;
    my $stash = $self->form->{stash};
    my $schema = $stash->{'schema'};
    my $resultset_name = $args->{resultset_name}; # || ucfirst $self->name;
    croak "Needs a DBIx::Class schema and a ResultSet class name"
    if ( ! $schema) || ( ! $resultset_name );
    my $rs = $schema->resultset( $resultset_name )->search( $args->{where},
        $args->{search_attr} );
    my $value_field = $args->{value_field} || 'id';
    my $presentation = $args->{presentation} || 'id';
    my @options = map { [ $_->$value_field, $_->$presentation ] } $rs->all;
    $self->options( \@options );
}

That would consume a config like:
---
elements:
   - type: Select::DBIC
     name: user
     options_from:
       resultset_name: User
       search_attr:
         order_by:
           - id

This is as simple as before - but there is one problem - it cannot use
'name' (to set 'resultset_name')  - since it looks like that even if
name is before 'options_from' in the config it is not yet set when
'options_from' is called.

And when you don't use the config you would have to call
'options_from' manually - just like you would call 'options'.

-- 
Zbigniew Lukasiak
http://brudnopis.blogspot.com/



More information about the HTML-FormFu mailing list