103 |
|
|
104 |
my $form; |
my $form; |
105 |
|
|
106 |
|
sub select_values { |
107 |
|
my ( $name, $attr_type, $values ) = @_; |
108 |
|
my $options = join("\n", |
109 |
|
map { |
110 |
|
my $v = ref($_) eq 'HASH' ? $_->{$name} : $_; |
111 |
|
qq|<option value="$v">$v</option>| if $v; |
112 |
|
} @$values |
113 |
|
); |
114 |
|
qq|<select title="$attr_type" name="$name">$options</select>| if $options; |
115 |
|
} |
116 |
|
|
117 |
foreach my $name ( grep { ! $class->meta->get_attribute($_)->is_lazy } $self->attributes ) { |
foreach my $name ( grep { ! $class->meta->get_attribute($_)->is_lazy } $self->attributes ) { |
118 |
my $attr_type = ''; |
my $attr_type = ''; |
119 |
my $type = $name =~ m/^pass/ ? 'password' : 'text'; |
my $type = $name =~ m/^pass/ ? 'password' : 'text'; |
121 |
my $value = ''; |
my $value = ''; |
122 |
my $label_title = ''; |
my $label_title = ''; |
123 |
my $value_html = ''; |
my $value_html = ''; |
124 |
|
|
125 |
|
my $attr = $class->meta->get_attribute( $name ); |
126 |
|
$attr_type = $attr->type_constraint->name if $attr->has_type_constraint; |
127 |
|
|
128 |
if ( ref($config_params) eq 'HASH' ) { |
if ( ref($config_params) eq 'HASH' ) { |
129 |
$value = $config_params->{$name}; |
$value = $config_params->{$name}; |
130 |
} elsif ( ref($config_params) eq 'ARRAY' ) { |
} elsif ( ref($config_params) eq 'ARRAY' ) { |
131 |
$value_html = qq|<select name="$name">| . join("\n", |
$value_html = select_values( $name, $attr_type, $config_params ); |
|
map { |
|
|
my $v = $_->{$name}; |
|
|
qq|<option value="$v">$v</option>| |
|
|
} @$config_params |
|
|
) . qq|</select>|; |
|
132 |
$default->{$name} = $config_params->[0]->{$name}; |
$default->{$name} = $config_params->[0]->{$name}; |
133 |
} elsif ( my $attr = $class->meta->get_attribute( $name ) ) { |
} elsif ( $attr->has_type_constraint && $attr->type_constraint->can('values') ) { |
134 |
if ( $attr->has_type_constraint ) { |
$value_html = select_values( $name, $attr_type, $attr->type_constraint->values ); |
135 |
$attr_type = $attr->type_constraint->name; |
} elsif ( $attr_type !~ m{^(Str|Int)$} ) { |
136 |
if ( $attr->type_constraint->can('values') ) { |
$value_html = qq|<textarea name="$name" title="$attr_type">$value</textarea>|; |
|
$value_html = qq|<select name="$name">| . join("\n", |
|
|
map { qq|<option value="$_">$_</option>| } @{ $attr->type_constraint->values } |
|
|
) . qq|</select>|; |
|
|
} elsif ( $attr_type !~ m{^(Str|Int)$} ) { |
|
|
$value_html = qq|<textarea name="$name" title="$attr_type">$value</textarea>|; |
|
|
} |
|
|
} |
|
|
$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"; |
|
137 |
} |
} |
138 |
|
$value = $attr->default( $name ) if ! $value && $attr->has_default; |
139 |
|
$label_title = qq| title="| . $attr->documentation . qq|"| if $attr->has_documentation; |
140 |
|
|
141 |
$default->{$name} = $value unless defined $default->{$name}; |
$default->{$name} = $value unless defined $default->{$name}; |
142 |
|
|
146 |
$form .= qq|<label for="$name"$label_title>$label</label>| . $value_html; |
$form .= qq|<label for="$name"$label_title>$label</label>| . $value_html; |
147 |
} |
} |
148 |
my $html = qq|<h1>$class params</h1><form method="post">$form<input type="submit" value="Run $class"></form>|; |
my $html = qq|<h1>$class params</h1><form method="post">$form<input type="submit" value="Run $class"></form>|; |
149 |
push @{ $self->status }, { |
$self->add_status({ |
150 |
$self->class => { |
$self->editor( $self->class ) => { |
151 |
params => $self->params, |
params => $self->params, |
152 |
config_params => $config_params, |
config_params => $config_params, |
153 |
default => $default |
default => $default |
154 |
}, |
}, |
155 |
}; |
}); |
156 |
|
|
157 |
return ($html,$default) if wantarray; |
return ($html,$default) if wantarray; |
158 |
return $html; |
return $html; |