|
NAMEVenus::Mixin - Mixin Builder ABSTRACTMixin Builder for Perl 5 SYNOPSIS package Person;
use Venus::Class 'attr';
attr 'fname';
attr 'lname';
package Identity;
use Venus::Mixin 'attr';
attr 'id';
attr 'login';
attr 'password';
sub EXPORT {
# explicitly declare routines to be consumed
['id', 'login', 'password']
}
package Authenticable;
use Venus::Role;
sub authenticate {
return true;
}
sub AUDIT {
my ($self, $from) = @_;
# ensure the caller has a login and password when consumed
die "${from} missing the login attribute" if !$from->can('login');
die "${from} missing the password attribute" if !$from->can('password');
}
sub BUILD {
my ($self, $data) = @_;
$self->{auth} = undef;
return $self;
}
sub EXPORT {
# explicitly declare routines to be consumed
['authenticate']
}
package User;
use Venus::Class;
base 'Person';
mixin 'Identity';
attr 'email';
test 'Authenticable';
sub valid {
my ($self) = @_;
return $self->login && $self->password ? true : false;
}
package main;
my $user = User->new(
fname => 'Elliot',
lname => 'Alderson',
);
# bless({fname => 'Elliot', lname => 'Alderson'}, 'User')
DESCRIPTIONThis package provides a mixin builder which when used causes the consumer to inherit from Venus::Core::Mixin which provides mixin building and lifecycle hooks. A mixin can do almost everything that a role can do but differs from a "role" in that whatever routines are declared using "export" will be exported and will overwrite routines of the same name in the consumer. FUNCTIONSThis package provides the following functions: attrattr(string $name) (string) The attr function creates attribute accessors for the calling package. This function is always exported unless a routine of the same name already exists. Since 1.00
basebase(string $name) (string) The base function registers one or more base classes for the calling package. This function is always exported unless a routine of the same name already exists. Since 1.00
catchcatch(coderef $block) (Venus::Error, any) The catch function executes the code block trapping errors and returning the caught exception in scalar context, and also returning the result as a second argument in list context. This function isn't export unless requested. Since 1.02
errorerror(maybe[hashref] $args) (Venus::Error) The error function throws a Venus::Error exception object using the exception object arguments provided. This function isn't export unless requested. Since 1.02
falsefalse() (boolean) The false function returns a falsy boolean value which is designed to be practically indistinguishable from the conventional numerical 0 value. This function is always exported unless a routine of the same name already exists. Since 1.00
fromfrom(string $name) (string) The from function registers one or more base classes for the calling package and performs an "audit". This function is always exported unless a routine of the same name already exists. Since 1.00
mixinmixin(string $name) (string) The mixin function registers and consumes mixins for the calling package. This function is always exported unless a routine of the same name already exists. Since 1.02
raiseraise(string $class | tuple[string, string] $class, maybe[hashref] $args) (Venus::Error) The raise function generates and throws a named exception object derived from Venus::Error, or provided base class, using the exception object arguments provided. This function isn't export unless requested. Since 1.02
rolerole(string $name) (string) The role function registers and consumes roles for the calling package. This function is always exported unless a routine of the same name already exists. Since 1.00
testtest(string $name) (string) The test function registers and consumes roles for the calling package and performs an "audit", effectively allowing a role to act as an interface. This function is always exported unless a routine of the same name already exists. Since 1.00
truetrue() (boolean) The true function returns a truthy boolean value which is designed to be practically indistinguishable from the conventional numerical 1 value. This function is always exported unless a routine of the same name already exists. Since 1.00
withwith(string $name) (string) The with function registers and consumes roles for the calling package. This function is an alias of the "test" function and will perform an "audit" if present. This function is always exported unless a routine of the same name already exists. Since 1.00
AUTHORSAwncorp, "awncorp@cpan.org" LICENSECopyright (C) 2022, Awncorp, "awncorp@cpan.org". This program is free software, you can redistribute it and/or modify it under the terms of the Apache license version 2.0.
|