Commit | Line | Data |
24185a7d |
1 | package Reaction::UI::ViewPort::Field::Mutable::MatchingPasswords; |
2 | |
3 | use Reaction::Class; |
81393881 |
4 | use namespace::clean -except => [ qw(meta) ]; |
7b5e71ad |
5 | use MooseX::Types::Moose qw/Str/; |
81393881 |
6 | |
d4667bef |
7 | extends 'Reaction::UI::ViewPort::Field::Mutable::Password'; |
81393881 |
8 | |
7b5e71ad |
9 | has check_value => (is => 'rw', isa => Str, ); |
10 | has check_label => (is => 'rw', isa => Str, lazy_build => 1); |
d4667bef |
11 | |
81393881 |
12 | sub _build_check_label { |
13 | my $orig_label = shift->label; |
14 | return "Confirm ${orig_label}"; |
d4667bef |
15 | } |
24185a7d |
16 | |
81393881 |
17 | #maybe both check_value and value_string should have triggers ? |
d4667bef |
18 | #that way if one even happens before the other it would still work? |
81393881 |
19 | around adopt_value_string => sub { |
20 | my $orig = shift; |
21 | my ($self) = @_; |
22 | return $orig->(@_) if $self->check_value eq $self->value_string; |
23 | $self->message("Passwords do not match"); |
24 | return; |
25 | }; |
26 | |
27 | #order is important check_value should happen before value here ... |
28 | #i don't like how this works, it's unnecessarily fragile, but how else ? |
29 | around accept_events => sub { ('check_value', shift->(@_)) }; |
30 | |
31 | around can_sync_to_action => sub { |
32 | my $orig = shift; |
33 | my ($self) = @_; |
34 | return $orig->(@_) if $self->check_value eq $self->value_string; |
35 | $self->message("Passwords do not match"); |
36 | return; |
37 | }; |
38 | |
39 | __PACKAGE__->meta->make_immutable; |
40 | |
24185a7d |
41 | 1; |
d4667bef |
42 | |
43 | __END__; |