improvements to MatchingPassword to have a better layout, label, and error messages...
[catagits/Reaction.git] / lib / Reaction / UI / ViewPort / Field / Mutable / MatchingPasswords.pm
CommitLineData
24185a7d 1package Reaction::UI::ViewPort::Field::Mutable::MatchingPasswords;
2
3use Reaction::Class;
4use aliased 'Reaction::UI::ViewPort::Field::Mutable::Password';
5
6class MatchingPasswords is Password, which {
7
8 has check_value => (is => 'rw', isa => 'Str', );
577fe414 9 has check_label => (is => 'rw', isa => 'Str', lazy_build => 1);
10
11 implements _build_check_label => as {
12 my $orig_label = shift->label;
13 return "Confirm ${orig_label}";
14 };
24185a7d 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?
283e06d6 18 around adopt_value_string => sub {
24185a7d 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");
577fe414 23 return;
24185a7d 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};
39
401;