fix matching passwords stuff
[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 namespace::clean -except => [ qw(meta) ];
5
6 extends 'Reaction::UI::ViewPort::Field::Mutable::Password';
7
8 has check_value => (is => 'rw', isa => 'Str', );
9 has check_label => (is => 'rw', isa => 'Str', lazy_build => 1);
10
11 sub _build_check_label {
12   my $orig_label = shift->label;
13   return "Confirm ${orig_label}";
14 }
15
16 #maybe both check_value and value_string should have triggers ?
17 #that way if one even happens before the other it would still work?
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
40 1;
41
42 __END__;