tobyink / p5-zydeco

Perl 5 distribution Zydeco; see homepage for downloads and documentation.
https://zydeco.toby.ink/
14 stars 3 forks source link

Example #3 from the main homepage doesn't run. #11

Open brickpool opened 3 years ago

brickpool commented 3 years ago

The following example "Powerful and concise attribute definitions." from the main homepage generates an exception.

package MyApp {
  use Zydeco;

  class Person {
    has name!    (type => Str);
    has age      (type => Int) = 0;
    has status   (
      enum        => ['alive', 'dead'],
      handles     => 1,
      default     => 'alive',
    );
    has children (
      is          => private,
      default     => sub { [] },
      handles_via => 'Array',
      handles     => { add_child => 'push', all_children => 'all' },
    );
  }
}

my $bob = MyApp->new_person(name => "Robert", age => 30);
$bob->is_dead;     # ==> false
$bob->add_child(
  MyApp->new_person(name => "Eve")
);

Here is the error message (perl v5.26.3 for MSWin32-x64-multi-thread)

Expected delegations to be a reference to an array; got HASH(0x53b6158) at c:/Perl64/site/lib/MooX/Press.pm line 1485.
BEGIN failed--compilation aborted at (eval 273)[c:/Perl64/site/lib/Zydeco.pm:2028] line 1.
 at c:/Perl64/site/lib/B/Hooks/EndOfScope/XS.pm line 26.
Execution of H:\temp\Array.pl aborted due to compilation errors.

It works with one of the following adjustments (yes, there are two ways to fix the code):

a) change is => private tois => rwp b) changehandles => {...} inhandles = > [...]