| 1 | package Rapi::Blog::PreAuth::Actor; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | |||
| 5 | # ABSTRACT: Base class for preauth Actors | ||
| 6 | |||
| 7 | use Moo; | ||
| 8 | use Types::Standard qw(:all); | ||
| 9 | |||
| 10 | use RapidApp::Util ':all'; | ||
| 11 | use Rapi::Blog::Util; | ||
| 12 | |||
| 13 | # Catalyst context: | ||
| 14 | has 'ctx', is => 'ro', required => 1; | ||
| 15 | |||
| 16 | has 'PreauthAction', | ||
| 17 | is => 'ro', | ||
| 18 | required => 1, | ||
| 19 | isa => InstanceOf['Rapi::Blog::DB::Result::PreauthAction']; | ||
| 20 | |||
| 21 | has 'info', is => 'rw', default => sub { '' } , isa => Str; | ||
| 22 | |||
| 23 | # If and what template the controller should render after execution | ||
| 24 | has 'render_template', is => 'rw', default => sub { undef } , isa => Maybe[Str]; | ||
| 25 | |||
| 26 | # Where the controller should redirect the user to after execution | ||
| 27 | # This takes priority over 'render_template' so child Actors should override | ||
| 28 | # the base setiing which is to just redirect the user to the site root | ||
| 29 | has 'redirect_url', is => 'rw', default => sub { '/' } , isa => Maybe[Str]; | ||
| 30 | |||
| 31 | sub req_params { (shift)->ctx->request->params } | ||
| 32 | |||
| 33 | sub is_error { 0 } | ||
| 34 | sub error_type { '' } | ||
| 35 | |||
| 36 | sub execute { ... } | ||
| 37 | |||
| 38 | |||
| 39 | sub call_execute { | ||
| 40 | my $self = shift; | ||
| 41 | |||
| 42 | my $ret = 0; | ||
| 43 | try { | ||
| 44 | $ret = $self->execute | ||
| 45 | } | ||
| 46 | catch { | ||
| 47 | my $err = shift; | ||
| 48 | $ret = 0; | ||
| 49 | $self->info( "$err" ) | ||
| 50 | }; | ||
| 51 | |||
| 52 | $self->post_execute; | ||
| 53 | |||
| 54 | $ret | ||
| 55 | } | ||
| 56 | |||
| 57 | |||
| 58 | sub post_execute { | ||
| 59 | my $self = shift; | ||
| 60 | $self->PreauthAction->_record_executed( $self->info ) | ||
| 61 | } | ||
| 62 | |||
| 63 | |||
| 64 | |||
| 65 | |||
| 66 | 1; | ||
| 67 | |||
| 68 | |||
| 69 | __END__ |