fix matching passwords stuff
[catagits/Reaction.git] / lib / Reaction / UI / ViewPort / Field / Mutable / MatchingPasswords.pm
CommitLineData
24185a7d 1package Reaction::UI::ViewPort::Field::Mutable::MatchingPasswords;
2
3use Reaction::Class;
81393881 4use namespace::clean -except => [ qw(meta) ];
81393881 5
d4667bef 6extends 'Reaction::UI::ViewPort::Field::Mutable::Password';
81393881 7
8has check_value => (is => 'rw', isa => 'Str', );
9has check_label => (is => 'rw', isa => 'Str', lazy_build => 1);
d4667bef 10
81393881 11sub _build_check_label {
12 my $orig_label = shift->label;
13 return "Confirm ${orig_label}";
d4667bef 14}
24185a7d 15
81393881 16#maybe both check_value and value_string should have triggers ?
d4667bef 17#that way if one even happens before the other it would still work?
81393881 18around 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 ?
28around accept_events => sub { ('check_value', shift->(@_)) };
29
30around 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
24185a7d 401;
d4667bef 41
42__END__;