--- trunk/lib/Frey/Action.pm 2008/11/17 14:37:48 369 +++ trunk/lib/Frey/Action.pm 2008/11/18 00:54:10 390 @@ -4,6 +4,7 @@ with 'Frey::Web'; with 'Frey::Config'; +use Clone qw/clone/; use Data::Dump qw/dump/; =head1 DESCRIPTION @@ -44,7 +45,7 @@ $attr->is_required && $attr; } $self->class->meta->get_attribute_list; - warn "## required = ",dump( map { $_->name } @required ), " for ", $self->class; + warn "## required = ",dump( map { $_->name } @required ), " for ", $self->class if @required && $self->debug; return @required if wantarray; return \@required; } @@ -65,14 +66,15 @@ my @attrs = @{ $self->attribute_order }; @attrs = map { $a->{$_}++; $_ } @attrs; push @attrs, $_ foreach grep { ! $a->{$_} } map { $_->name } @{ $self->required }; - warn "# attributes = ",dump( @attrs ); + warn "# attributes = ",dump( @attrs ) if $self->debug; return @attrs if wantarray; return \@attrs; } =head2 params_form - my $html = $self->params_form; + my $html = $self->params_form; + my ($html,$default_params) = $self->params_form; =cut @@ -81,51 +83,74 @@ my @required = $self->required; if ( ! @required ) { warn "all params available ", dump( $self->params ), " not creating form"; + return (undef,$self->params) if wantarray; return; } else { - warn $self->class, " required params ", dump( @required ); + warn $self->class, " required params ", map { $_->dump(2) } @required if $self->debug; } my $class = $self->class; $self->load_class( $class ); - my $params = {}; - $params = $self->config($class); - warn "# $class config = ",dump( $params ) if $self->debug; + my $default = clone $self->params; # XXX we really don't want to modify params! - my $html = qq|

$class params

|; + my $config_params = {}; + $config_params = $self->config($class); + warn "# $class config = ",dump( $config_params ) if $self->debug; + + my $form; foreach my $name ( grep { ! $class->meta->get_attribute($_)->is_lazy } $self->attributes ) { + my $attr_type; my $type = $name =~ m/^pass/ ? 'password' : 'text'; + my $label = $name; my $value = ''; + my $label_title = ''; my $value_html = ''; - if ( ref($params) eq 'HASH' ) { - $value = $params->{$name}; - } elsif ( ref($params) eq 'ARRAY' ) { + if ( ref($config_params) eq 'HASH' ) { + $value = $config_params->{$name}; + } elsif ( ref($config_params) eq 'ARRAY' ) { $value_html = qq||; + $default->{$name} = $config_params->[0]->{$name}; } elsif ( my $attr = $class->meta->get_attribute( $name ) ) { - if ( $attr->has_type_constraint && $attr->type_constraint->can('values') ) { - $value_html = qq||; - } elsif ( $attr->has_default ) { - $value = $attr->default( $name ); + $attr_type = $attr->type_constraint->name; + if ( $attr->has_type_constraint ) { + 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"; } - $value_html = qq|| unless $value_html; + + $value_html = qq|| unless $value_html; + + $default->{$name} = $value unless defined $default->{$name}; + # warn "# required $name ", $class->meta->get_attribute( $name )->dump( 2 ); - $html .= qq|| . $value_html; + $form .= qq|| . $value_html; } - $html .= qq|
|; + my $html = qq|

$class params

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