From: Mischa POSLAWSKY Date: Thu, 22 Jul 2021 15:56:49 +0000 (+0200) Subject: word/edit: move FormRow class into separate file X-Git-Tag: v1.13~175 X-Git-Url: http://git.shiar.net/sheet.git/commitdiff_plain/e26741ab236cbfaa89aa82d121c224137801a63b word/edit: move FormRow class into separate file --- diff --git a/Shiar_Sheet/FormRow.pm b/Shiar_Sheet/FormRow.pm new file mode 100644 index 0000000..03f1c22 --- /dev/null +++ b/Shiar_Sheet/FormRow.pm @@ -0,0 +1,65 @@ +package Shiar_Sheet::FormRow; + +use 5.014; +use warnings; +use PLP::Functions 'EscapeHTML'; + +our $VERSION = '1.00'; + +sub input { + my ($row, $col, $attr) = @_; + my $val = $row->{$col} // ''; + my $html = ''; + $html .= qq( $_="$attr->{$_}") for sort grep {!/^-/} keys %{$attr // {}}; + + if (my $options = $attr->{-select}) { + $options = $options->(@_) if ref $options eq 'CODE'; + $options->{$val} //= "unknown ($val)"; # preserve current + return ( + sprintf('', + ); + } + elsif ($attr->{type} eq 'textarea') { + return ( + (map { + sprintf('', $col, $_) + } $attr->{-label} // ()), + sprintf('', + $col, $html, EscapeHTML($val) + ), + ); + } + elsif ($attr->{type} eq 'checkbox') { + $html .= ' checked' if $val; + return sprintf( + join('', + '', + ), $col, $html, $attr->{-label} + ); + } + else { + my $multiple = ref $val eq 'ARRAY' || $attr->{-multiple}; + return ( + (map { + sprintf('', $col, $_) + } $attr->{-label} // ()), + $multiple ? '' : (), + (map { + sprintf('', $col, EscapeHTML($_)) + } ref $val eq 'ARRAY' ? @{$val} : ()), + sprintf('', + $col, $multiple ? '' : EscapeHTML($val), $html + ), + $multiple ? '' : (), + ); + } +} + +1; diff --git a/writer.plp b/writer.plp index 275819b..b5f5032 100644 --- a/writer.plp +++ b/writer.plp @@ -11,6 +11,7 @@ EOT }); use List::Util qw( pairs pairkeys ); +use Shiar_Sheet::FormRow; my $db = eval { require Shiar_Sheet::DB; @@ -257,66 +258,6 @@ else { } my $title = $row->{id} ? "entry #$row->{id}" : 'new entry'; - -package Shiar_Sheet::FormRow { - use PLP::Functions 'EscapeHTML'; - - sub input { - my ($row, $col, $attr) = @_; - my $val = $row->{$col} // ''; - my $html = ''; - $html .= qq( $_="$attr->{$_}") for sort grep {!/^-/} keys %{$attr // {}}; - - if (my $options = $attr->{-select}) { - $options = $options->(@_) if ref $options eq 'CODE'; - $options->{$val} //= "unknown ($val)"; # preserve current - return ( - sprintf('', - ); - } - elsif ($attr->{type} eq 'textarea') { - return ( - (map { - sprintf('', $col, $_) - } $attr->{-label} // ()), - sprintf('', - $col, $html, EscapeHTML($val) - ), - ); - } - elsif ($attr->{type} eq 'checkbox') { - $html .= ' checked' if $val; - return sprintf( - join('', - '', - ), $col, $html, $attr->{-label} - ); - } - else { - my $multiple = ref $val eq 'ARRAY' || $attr->{-multiple}; - return ( - (map { - sprintf('', $col, $_) - } $attr->{-label} // ()), - $multiple ? '' : (), - (map { - sprintf('', $col, EscapeHTML($_)) - } ref $val eq 'ARRAY' ? @{$val} : ()), - sprintf('', - $col, $multiple ? '' : EscapeHTML($val), $html - ), - $multiple ? '' : (), - ); - } - } -} bless $row, 'Shiar_Sheet::FormRow'; :>

Words <:= $title :>