rewrite IM predicates
[catagits/Reaction.git] / lib / Reaction / InterfaceModel / Action / User / Login.pm
1 package Reaction::InterfaceModel::Action::User::Login;
2
3 use Reaction::Class;
4 use aliased 'Reaction::InterfaceModel::Action';
5 use Reaction::Types::Core qw(SimpleStr Password);
6
7 class Login, is Action, which {
8
9   has 'username' => (isa => SimpleStr, is => 'rw', lazy_fail => 1);
10   has 'password' => (isa => Password,  is => 'rw', lazy_fail => 1);
11
12   around error_for_attribute => sub {
13     my $super = shift;
14     my ($self, $attr) = @_;
15     my $result = $super->(@_);
16     my $predicate = $attr->get_predicate_method;
17     if (defined $result && $self->$predicate) {
18       return 'Invalid username or password';
19     }
20     return;
21   };
22
23   implements do_apply => as {
24     my $self = shift;
25     my $target = $self->target_model;
26     return $target->login($self->username, $self->password);
27   };
28 };
29
30 1;
31
32 =head1 NAME
33
34 Reaction::InterfaceModel::Action::User::Login
35
36 =head1 DESCRIPTION
37
38 =head2 username
39
40 =head2 password
41
42 =head1 AUTHORS
43
44 See L<Reaction::Class> for authors.
45
46 =head1 LICENSE
47
48 See L<Reaction::Class> for the license.
49
50 =cut