| 1 | package WebService::Mattermost::V4::API::Role::RequireID; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # ABSTRACT: ID validation. | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 13 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 13 | ▶ | use Types::Standard 'RegexpRef'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 13 | requires 'error_return'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | ################################################################################ | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1685 | ▶ | has id_validation_regexp => (is => 'ro', isa => RegexpRef, default => sub { qr{(?i)^[a-z0-9\-]+$} }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | ################################################################################ | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | sub validate_id { | ||||||||||||||||||||||||||||
| 17 | 10 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
validate_id: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | 10 | my $next = shift; | |||||||||||||||||||||||||||
| 19 | 10 | ▶ | my $id = shift || $self->id; | ||||||||||||||||||||||||||
|
Condition100%3/3
shift() || $self->id
MC/DC100%2/2
shift() || $self->id
shift()
$self->id
Truth table100%3/3
A || B
A= shift()B= $self->id
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 10 | ▶ | if ($self->validate_id_no_next($id)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 7 | return $self->$next($id, @_); | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 3 | return $self->error_return('Invalid or missing ID parameter'); | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | sub validate_id_no_next { | ||||||||||||||||||||||||||||
| 29 | 10 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
validate_id_no_next: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 30 | 10 | ▶ | my $id = shift || $self->id; | ||||||||||||||||||||||||||
|
Condition66%2/3
shift() || $self->id
MC/DC50%1/2
shift() || $self->id
shift()
$self->id
Truth table66%2/3
A || B
A= shift()B= $self->id
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 10 | ▶ | return ($id && $id =~ $self->id_validation_regexp) ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$id and $id =~ $self->id_validation_regexp
MC/DC100%2/2
$id and $id =~ $self->id_validation_regexp
$id
$id =~ $self->id_validation_regexp
Truth table100%3/3
A and B
A= $idB= $id =~ $self->id_validation_regexp
| |||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | ################################################################################ | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 13 | 1; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | __END__ | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =pod | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | =head1 NAME | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | WebService::Mattermost::V4::API::Role::RequireID - ID validation. | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | =head1 VERSION | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | version 0.28 | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | Validate that the first parameter passed to a subroutine is a valid UUID for | ||||||||||||||||||||||||||||
| 56 | Mattermost. | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | =head2 METHODS | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | =over 4 | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | =item C<validate_id()> | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | Validate the ID and run the next subroutine. | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | =item C<validate_id_no_next()> | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | Validate the ID but do not run the next subroutine. | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =back | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =head2 ATTRIBUTES | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | =over 4 | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | =item C<id_validation_regexp> | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | Basic UUID matching regular expression. | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | =back | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | Mike Jones <mike@netsplit.org.uk> | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | This software is Copyright (c) 2020 by Mike Jones. | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | This is free software, licensed under: | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | The MIT (X11) License | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | =cut | ||||||||||||||||||||||||||||