aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Reaction/UI/ViewPort/Field/Mutable/MatchingPasswords.pm
blob: 845b8b592b6d729ebcc46fb728c41d75a15f428c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package Reaction::UI::ViewPort::Field::Mutable::MatchingPasswords;

use Reaction::Class;
use namespace::clean -except => [ qw(meta) ];

extends 'Reaction::UI::ViewPort::Field::Mutable::Password';

has check_value => (is => 'rw', isa => 'Str', );
has check_label => (is => 'rw', isa => 'Str', lazy_build => 1);

sub _build_check_label {
  my $orig_label = shift->label;
  return "Confirm ${orig_label}";
}

#maybe both check_value and value_string should have triggers ?
#that way if one even happens before the other it would still work?
around adopt_value_string => sub {
  my $orig = shift;
  my ($self) = @_;
  return $orig->(@_) if $self->check_value eq $self->value_string;
  $self->message("Passwords do not match");
  return;
};

#order is important check_value should happen before value here ...
#i don't like how this works, it's unnecessarily fragile, but how else ?
around accept_events => sub { ('check_value', shift->(@_)) };

around can_sync_to_action => sub {
  my $orig = shift;
  my ($self) = @_;
  return $orig->(@_) if $self->check_value eq $self->value_string;
  $self->message("Passwords do not match");
  return;
};

__PACKAGE__->meta->make_immutable;

1;

__END__;