The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

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:

Data::Object::Library

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.

aftr_settings example
my $aftr_settings = aftr_settings();

arnd_settings

arnd_settings(Str $arg1, Object $arg2) : (Str, HashRef)

The arnd_settings function returns the around-keyword configuration.

arnd_settings example
my $arnd_settings = arnd_settings();

befr_settings

befr_settings(Str $arg1, Object $arg2) : (Str, HashRef)

The befr_settings function returns the before-keyword configuration.

befr_settings example
my $befr_settings = befr_settings();

func_settings

func_settings(Str $arg1, Object $arg2) : (Str, HashRef)

The func_settings function returns the fun-keyword configuration.

func_settings example
my $func_settings = func_settings();

meth_settings

meth_settings(Str $arg1, Object $arg2) : (Str, HashRef)

The meth_settings function returns the method-keyword configuration.

meth_settings example
my $meth_settings = meth_settings();

settings

settings(Str $arg1, Any @args) : HashRef

The settings function returns the settings for Function::Parameters configuration.

settings example
my $settings = settings();

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

Wiki

Project

Initiatives

Milestones

Contributing

Issues

SEE ALSO

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

Data::Object::Library