Data::Object::Signatures
Data-Object Method Signatures
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; }
This package provides method and function signatures supporting all the type constraints provided by Data::Object::Library.
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:
Cart
App
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;
This package uses type constraints defined by:
Data::Object::Library
This package implements the following functions.
aftr_settings(Str $arg1, Object $arg2) : (Str, HashRef)
The aftr_settings function returns the after-keyword configuration.
my $aftr_settings = aftr_settings();
arnd_settings(Str $arg1, Object $arg2) : (Str, HashRef)
The arnd_settings function returns the around-keyword configuration.
my $arnd_settings = arnd_settings();
befr_settings(Str $arg1, Object $arg2) : (Str, HashRef)
The befr_settings function returns the before-keyword configuration.
my $befr_settings = befr_settings();
func_settings(Str $arg1, Object $arg2) : (Str, HashRef)
The func_settings function returns the fun-keyword configuration.
my $func_settings = func_settings();
meth_settings(Str $arg1, Object $arg2) : (Str, HashRef)
The meth_settings function returns the method-keyword configuration.
my $meth_settings = meth_settings();
settings(Str $arg1, Any @args) : HashRef
The settings function returns the settings for Function::Parameters configuration.
my $settings = settings();
Al Newkirk, +319
+319
Anthony Brummett, +10
+10
Adam Hopkins, +2
+2
José Joaquín Atria, +1
+1
Al Newkirk, awncorp@cpan.org
awncorp@cpan.org
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.
Wiki
Project
Initiatives
Milestones
Contributing
Issues
To get the most out of this distribution, consider reading the following:
Do
Data::Object
Data::Object::Class
Data::Object::ClassHas
Data::Object::Role
Data::Object::RoleHas
To install Do, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Do
CPAN shell
perl -MCPAN -e shell install Do
For more information on module installation, please visit the detailed CPAN module installation guide.