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