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