20 |
|
|
21 |
=cut |
=cut |
22 |
|
|
23 |
sub runnable { qw/data markup/ } |
use Moose::Util::TypeConstraints; |
24 |
|
|
25 |
|
enum 'Runnable' => qw/data markup sponge/; |
26 |
|
|
27 |
|
sub runnable { qw/data markup sponge/ } |
28 |
|
|
29 |
has 'class' => ( |
has 'class' => ( |
30 |
is => 'rw', |
is => 'rw', |
38 |
default => sub { {} }, |
default => sub { {} }, |
39 |
); |
); |
40 |
|
|
41 |
|
has 'run' => ( |
42 |
|
is => 'rw', |
43 |
|
isa => 'Runnable', |
44 |
|
); |
45 |
|
|
46 |
sub html { |
sub html { |
47 |
my ( $self ) = @_; |
my ( $self ) = @_; |
48 |
|
|
77 |
foreach my $name ( @attrs ) { |
foreach my $name ( @attrs ) { |
78 |
my $attr = $class->meta->get_attribute( $name ); |
my $attr = $class->meta->get_attribute( $name ); |
79 |
my $type = $name =~ m/^pass/ ? 'password' : 'text'; |
my $type = $name =~ m/^pass/ ? 'password' : 'text'; |
80 |
my $value = |
my $value = ''; |
81 |
$values ? $values->{$name} : |
my $value_html = ''; |
82 |
$attr->has_default ? $attr->default( $name ) : |
if ( ref($values) eq 'HASH' ) { |
83 |
''; |
$value = $values->{$name}; |
84 |
|
} elsif ( ref($values) eq 'ARRAY' ) { |
85 |
|
$value_html = qq|<select name="$name">| . join("\n", |
86 |
|
map { |
87 |
|
my $v = $_->{$name}; |
88 |
|
qq|<option value="$v">$v</option>| |
89 |
|
} @$values |
90 |
|
) . qq|</select>|; |
91 |
|
} elsif ( $attr->has_type_constraint && $attr->type_constraint->can('values') ) { |
92 |
|
$value_html = qq|<select name="$name">| . join("\n", |
93 |
|
map { qq|<option value="$_">$_</option>| } @{ $attr->type_constraint->values } |
94 |
|
) . qq|</select>|; |
95 |
|
} elsif ( $attr->has_default ) { |
96 |
|
$value = $attr->default( $name ); |
97 |
|
} |
98 |
|
$value_html = qq|<input type="$type" name="$name" value="$value">| unless $value_html; |
99 |
|
|
100 |
#warn "# required $name ", $class->meta->get_attribute( $name )->dump( 2 ); |
#warn "# required $name ", $class->meta->get_attribute( $name )->dump( 2 ); |
101 |
$html .= qq|<label for="$name">$name</label><input type="$type" name="$name" value="$value">|; |
$html .= qq|<label for="$name">$name</label>| . $value_html; |
102 |
} |
} |
103 |
$html .= qq|<input type="submit" value="Run $class"></form>|; |
$html .= qq|<input type="submit" value="Run $class"></form>|; |
104 |
} else { |
} else { |
112 |
$html .= qq{<code>$@</code>}; |
$html .= qq{<code>$@</code>}; |
113 |
} |
} |
114 |
warn ">>> markup $class ",length( $html ), " bytes\n"; |
warn ">>> markup $class ",length( $html ), " bytes\n"; |
115 |
|
} elsif ( $o->can('sponge') ) { |
116 |
|
my $data = $o->sponge; |
117 |
|
$html .= '<table>'; |
118 |
|
$html .= '<tr><th>' . join('</th><th>', @{$data->{NAME}} ) . '</th></tr>'; |
119 |
|
$html .= '<tr><td>' . join('</td><td>', @$_ ) . '</td></tr>' foreach @{ $data->{rows} }; |
120 |
|
$html .= '</table>'; |
121 |
} elsif ( $o->can('data') ) { |
} elsif ( $o->can('data') ) { |
122 |
my $data = $o->data; |
my $data = $o->data; |
123 |
$html .= Frey::Dumper->new( data => $data )->markup; |
$html .= Frey::Dumper->new( data => $data )->markup; |