Skip to content

Instantly share code, notes, and snippets.

@tobyink
Last active September 14, 2020 22:40
Show Gist options
  • Select an option

  • Save tobyink/75f26790b7a9503e09c91a01e950b8f5 to your computer and use it in GitHub Desktop.

Select an option

Save tobyink/75f26790b7a9503e09c91a01e950b8f5 to your computer and use it in GitHub Desktop.
Example from the Zydeco pod
use v5.14;
use strict;
use warnings;
package MyApp {
use Zydeco;
class Person {
has name ( type => Str, required => true );
has gender ( type => Str );
factory new_man ( Str $name ) {
return $class->new( name => $name, gender => 'male' );
}
factory new_woman ( Str $name ) {
return $class->new( name => $name, gender => 'female' );
}
method greet ( Person *friend, Str *greeting = "Hello" ) {
printf( "%s, %s!\n", $arg->greeting, $arg->friend->name );
}
coerce from Str via from_string {
return $class->new( name => $_ );
}
}
}
'MyApp'->new_woman( 'Alice' )->greet( friend => 'Bob' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment