| 1 | package Venus::Role::Rejectable; | ||
| 2 | |||
| 3 | 1 | ▶ | use 5.018; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | # IMPORTS | ||
| 9 | |||
| 10 | 1 | ▶ | use Venus::Role 'with'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | |||
| 12 | # BUILDERS | ||
| 13 | |||
| 14 | 1 | ▶ | sub BUILD { |
|
Subroutine
BUILD: called CC=2 SCAR=6.9
Pod
undocumented
| |||
| 15 | 1 | my ($self) = @_; | |
| 16 | |||
| 17 | 1 | my %attrs = map +($_, $_), $self->META->attrs; | |
| 18 | 1 | my @unknowns = sort grep !exists($attrs{$_}), keys %$self; | |
| 19 | 1 | delete $self->{$_} for @unknowns; | |
| 20 | |||
| 21 | 1 | return $self; | |
| 22 | } | ||
| 23 | |||
| 24 | 1 | 1; | |
| 25 | |||
| 26 | |||
| 27 | |||
| 28 | =head1 NAME | ||
| 29 | |||
| 30 | Venus::Role::Rejectable - Rejectable Role | ||
| 31 | |||
| 32 | =cut | ||
| 33 | |||
| 34 | =head1 ABSTRACT | ||
| 35 | |||
| 36 | Rejectable Role for Perl 5 | ||
| 37 | |||
| 38 | =cut | ||
| 39 | |||
| 40 | =head1 SYNOPSIS | ||
| 41 | |||
| 42 | package ExampleAccept; | ||
| 43 | |||
| 44 | use Venus::Class 'attr'; | ||
| 45 | |||
| 46 | attr 'name'; | ||
| 47 | |||
| 48 | package ExampleReject; | ||
| 49 | |||
| 50 | use Venus::Class 'attr', 'with'; | ||
| 51 | |||
| 52 | with 'Venus::Role::Rejectable'; | ||
| 53 | |||
| 54 | attr 'name'; | ||
| 55 | |||
| 56 | package main; | ||
| 57 | |||
| 58 | my $example = ExampleReject->new(name => 'example', test => 12345); | ||
| 59 | |||
| 60 | # bless({name => 'example'}, "Example") | ||
| 61 | |||
| 62 | =cut | ||
| 63 | |||
| 64 | =head1 DESCRIPTION | ||
| 65 | |||
| 66 | This package provides a mechanism for rejecting unexpected constructor arguments. | ||
| 67 | |||
| 68 | =cut | ||
| 69 | |||
| 70 | =head1 AUTHORS | ||
| 71 | |||
| 72 | Awncorp, C<awncorp@cpan.org> | ||
| 73 | |||
| 74 | =cut | ||
| 75 | |||
| 76 | =head1 LICENSE | ||
| 77 | |||
| 78 | Copyright (C) 2022, Awncorp, C<awncorp@cpan.org>. | ||
| 79 | |||
| 80 | This program is free software, you can redistribute it and/or modify it under | ||
| 81 | the terms of the Apache license version 2.0. | ||
| 82 | |||
| 83 | =cut | ||