The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Authorization::AccessControl::Dispatch - Dispatch result/status appropriately following ACL request yield

SYNOPSIS

use Authorization::AccessControl::Dispatch;

my $dispatch = Authorization::AccessControl::Dispatch->new(
  granted => 1,
  entity => 'some secure value');

$dispatch->denied(...); # not called
$dispatch->null(...); # not called
$dispatch->granted(sub($val) { $c->render(text => $val) }); # renders value

$request->yield(sub(){...})
  ->granted(sub($val) { #handle success 
  })
  ->denied(sub() { # handle denial
  })
  ->null(sub() { # handle not found
  })

Handlers can be repeated:

$request->yield(sub(){...})
  ->granted(sub($value){ $c->render(json => $value) })
  ->granted(\&write_audit_log)

DESCRIPTION

This is a lightweight class that simply facilitates a "promise-style" callback interface for dealing with the result of yield in Authorization::AccessControl::Request

Dispatch instances are immutable: none of their properties may be altered after object creation.

METHODS

new

Authorization::AccessControl::Dispatch->new(granted => [0|1|undef], entity => ...)

Creates a new Dispatch instance. granted is a trinary value reflecting the request status: "truthy" indicates permitted, "falsy" indicates denied, and undefined indicates that necessary attributes could not be evaluated because the data value was not present. entity is the data value, to be passed to "granted" handlers. If granted is anything but "truthy", the entity value is immediately undefined before proceeding.

granted

$dispatch->granted(sub($result){...})

Registers a handler to be executed when the request is permitted by the ACL. Handler receives one argument: the yielded value

Repeatable. Chainable.

denied

$dispatch->denied(sub(){...})

Registers a handler to be executed when the request is denied by the ACL. Handler receives no arguments.

Repeatable. Chainable.

null

$dispatch->null(sub(){ ... })

Registers a handler to be executed when the yielded value is undefined. Handler receives no arguments.

Repeatable. Chainable.

is_granted

$dispatch->is_granted()

Returns a boolean value reflecting whether or not the request was permitted by the ACL

AUTHOR

Mark Tyrrell <mark@tyrrminal.dev>

LICENSE

Copyright (c) 2024 Mark Tyrrell

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.