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