move redirect_to to a role and deprecate it
[catagits/Reaction.git] / lib / Reaction / UI / ViewPort / Field / Mutable / File.pm
1 package Reaction::UI::ViewPort::Field::Mutable::File;
2
3 use Reaction::Types::File qw/Upload/;
4 use Reaction::Class;
5
6 use namespace::clean -except => [ qw(meta) ];
7 extends 'Reaction::UI::ViewPort::Field';
8
9 with 'Reaction::UI::ViewPort::Field::Role::Mutable::Simple';
10
11 has '+value' => (isa => Upload);
12
13 override apply_our_events => sub {
14   my ($self, $events) = @_;
15   my $value_key = $self->event_id_for('value_string');
16   if (my $upload = $self->ctx->req->upload($value_key)) {
17     local $events->{$value_key} = $upload;
18     return super();
19   } else {
20     return super();
21   }
22 };
23 sub adopt_value_string {
24     my($self) = @_;
25     $self->value($self->value_string) if $self->value_string;
26 };
27 override _value_string_from_value => sub { '' };
28
29 __PACKAGE__->meta->make_immutable;
30
31
32 1;