--- trunk/lib/Frey/Action.pm 2008/11/19 00:39:23 430 +++ trunk/lib/Frey/Action.pm 2008/11/28 17:18:56 595 @@ -37,19 +37,14 @@ my ( $self ) = @_; $self->load_class( $self->class ); my @required = - grep { defined $_ } - map { - eval { - $_->can('name') && !defined( $self->params->{ $_->name } ) - }; - } grep { - my $required = eval { - my $attr = $self->class->meta->get_attribute($_); - $attr->is_required; - }; - warn "# attribute $_ error: $@" if $@; - $required; + defined $_ && $_->can('name') && + ! defined( $self->params->{ $_->name } ) && + ! $_->is_lazy + } + map { + my $attr = $self->class->meta->get_attribute($_); + blessed $attr && $attr->is_required && $attr; } $self->class->meta->get_attribute_list; warn "## required = ",dump( map { $_->name } @required ), " for ", $self->class if @required && $self->debug; @@ -108,6 +103,17 @@ my $form; + sub select_values { + my ( $name, $attr_type, $values ) = @_; + my $options = join("\n", + map { + my $v = ref($_) eq 'HASH' ? $_->{$name} : $_; + qq|| if $v; + } @$values + ); + qq|| if $options; + } + foreach my $name ( grep { ! $class->meta->get_attribute($_)->is_lazy } $self->attributes ) { my $attr_type = ''; my $type = $name =~ m/^pass/ ? 'password' : 'text'; @@ -115,47 +121,47 @@ my $value = ''; my $label_title = ''; my $value_html = ''; + + my $attr = $class->meta->get_attribute( $name ); + $attr_type = $attr->type_constraint->name if $attr->has_type_constraint; + + $value = $attr->default( $name ) if ! $value && $attr->has_default; + if ( ref($config_params) eq 'HASH' ) { $value = $config_params->{$name}; } elsif ( ref($config_params) eq 'ARRAY' ) { - $value_html = qq||; + $value_html = select_values( $name, $attr_type, $config_params ); $default->{$name} = $config_params->[0]->{$name}; - } elsif ( my $attr = $class->meta->get_attribute( $name ) ) { - if ( $attr->has_type_constraint ) { - $attr_type = $attr->type_constraint->name; - if ( $attr->type_constraint->can('values') ) { - $value_html = qq||; - } elsif ( $attr_type !~ m{^(Str|Int)$} ) { - $value_html = qq||; - } - } - $value = $attr->default( $name ) if ! $value && $attr->has_default; - $label_title = qq| title="| . $attr->documentation . qq|"| if $attr->has_documentation; - } else { - warn "wired attribute $name"; + } elsif ( $attr->has_type_constraint && $attr->type_constraint->can('values') ) { + $value_html = select_values( $name, $attr_type, $attr->type_constraint->values ); + } elsif ( $attr_type !~ m{^(Str|Int)$} ) { + $value_html = qq||; } - - $value_html = qq|| unless $value_html; + + $label_title = qq| title="| . $attr->documentation . qq|"| if $attr->has_documentation; $default->{$name} = $value unless defined $default->{$name}; + if ( ! $value_html ) { + my $suffix = ''; + if ( $attr_type =~ m{^Bool$} ) { + $type = 'checkbox'; + $suffix = ' checked' if $value; + } + $value_html = qq||; + } + # warn "# required $name ", $class->meta->get_attribute( $name )->dump( 2 ); $form .= qq|| . $value_html; } my $html = qq|

$class params

$form
|; - push @{ $self->status }, { 'Params' => - { - 'Config' => $config_params, - 'Default' => $default + $self->add_status({ + $self->class => { + params => $self->params, + config_params => $config_params, + default => $default }, - }; + }); return ($html,$default) if wantarray; return $html;