bbe992f7b4411cb8ed7ccf26b06cc6d217af3506
[catagits/Reaction.git] / lib / Reaction / UI / ViewPort / Field / Mutable / MatchingPasswords.pm
1 package Reaction::UI::ViewPort::Field::Mutable::MatchingPasswords;
2
3 use Reaction::Class;
4 use aliased 'Reaction::UI::ViewPort::Field::Mutable::Password';
5
6 class MatchingPasswords is Password, which {
7
8   has check_value => (is => 'rw', isa => 'Str', );
9
10   #maybe both check_value and value_string should have triggers ?
11   #that way if one even happens before the other  it would still work?
12   around adopt_value_string => sub {
13     my $orig = shift;
14     my ($self) = @_;
15     return $orig->(@_) if $self->check_value eq $self->value_string;
16     $self->message("Passwords do not match");
17   };
18
19   #order is important check_value should happen before value here ...
20   #i don't like how this works, it's unnecessarily fragile, but how else ?
21   around accept_events => sub { ('check_value', shift->(@_)) };
22
23   around can_sync_to_action => sub {
24     my $orig = shift;
25     my ($self) = @_;
26     return $orig->(@_) if $self->check_value eq $self->value_string;
27     $self->message("Passwords do not match");
28     return;
29   };
30
31 };
32
33 1;