Last active
September 14, 2020 22:40
-
-
Save tobyink/75f26790b7a9503e09c91a01e950b8f5 to your computer and use it in GitHub Desktop.
Example from the Zydeco pod
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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