Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
brickpool opened this issue May 7, 2021 · 0 comments
Open

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

brickpool opened this issue May 7, 2021 · 0 comments

Comments

@brickpool
Copy link

brickpool commented May 7, 2021

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 to is => rwp
b) change handles => {...} inhandles = > [...]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant