NAME
Data::Object::Signatures
ABSTRACT
Data-Object Method Signatures
SYNOPSIS
use Data::Object::Signatures;
fun hello (Str $name) {
return "Hello $name, how are you?";
}
before created() {
# do something ...
return $self;
}
after created() {
# do something ...
return $self;
}
around updated() {
# do something ...
$self->$orig;
# do something ...
return $self;
}
DESCRIPTION
This package provides method and function signatures supporting all the type constraints provided by Data::Object::Library.
FOREWARNING
Please note that function and method signatures do support parameterized types but with certain caveats. For example, consider the following:
package App::Store;
use Do 'Class', 'App';
method checkout(InstanceOf[Cart] $cart) {
# perform store checkout
}
1;
This method signature is valid so long as the Cart
type is registered in the user-defined App
type library. However, in the case where that type is not in the type library, you might be tempted to use the fully-qualified class name, for example:
package App::Store;
use Do 'Class', 'App';
method checkout(InstanceOf[App::Cart] $cart) {
# perform store checkout
}
1;
Because the type portion of the method signature is evaluated as a Perl string that type declaration is not valid and will result in a syntax error due to the signature parser not expecting the bareword. You might then be tempted to simply quote the fully-qualified class name, for example:
package App::Store;
use Do 'Class', 'App';
method checkout(InstanceOf["App::Cart"] $cart) {
# perform store checkout
}
1;
TLDR; The signature parser doesn't like that either. To resolve this issue you have two potential solutions, the first being to declare the Cart
type in the user-defined library, for example:
package App;
use Do 'Library';
our $Cart = declare 'Cart',
as InstanceOf["App::Cart"];
package App::Store;
use Do 'Class', 'App';
method checkout(Cart $cart) {
# perform store checkout
}
1;
Or, alternatively, you could express the type declaration as a string which the parser will except and evaluate properly, for example:
package App::Store;
use Do 'Class';
method checkout(('InstanceOf["App::Cart"]') $cart) {
# perform store checkout
}
1;
LIBRARIES
This package uses type constraints defined by:
FUNCTIONS
This package implements the following functions.
aftr_settings
aftr_settings(Str $arg1, Object $arg2) : (Str, HashRef)
The aftr_settings function returns the after-keyword configuration.
arnd_settings
arnd_settings(Str $arg1, Object $arg2) : (Str, HashRef)
The arnd_settings function returns the around-keyword configuration.
befr_settings
befr_settings(Str $arg1, Object $arg2) : (Str, HashRef)
The befr_settings function returns the before-keyword configuration.
func_settings
func_settings(Str $arg1, Object $arg2) : (Str, HashRef)
The func_settings function returns the fun-keyword configuration.
meth_settings
meth_settings(Str $arg1, Object $arg2) : (Str, HashRef)
The meth_settings function returns the method-keyword configuration.
settings
settings(Str $arg1, Any @args) : HashRef
The settings function returns the settings for Function::Parameters configuration.
CREDITS
Al Newkirk, +319
Anthony Brummett, +10
Adam Hopkins, +2
José Joaquín Atria, +1
AUTHOR
Al Newkirk, awncorp@cpan.org
LICENSE
Copyright (C) 2011-2019, Al Newkirk, et al.
This is free software; you can redistribute it and/or modify it under the terms of the The Apache License, Version 2.0, as elucidated here, https://github.com/iamalnewkirk/do/blob/master/LICENSE.
PROJECT
SEE ALSO
To get the most out of this distribution, consider reading the following: