Do MooseX :: AttributeHelpers and MooseX :: FollowPBP interact correctly?

The following code defines two classes ( DeckAand DeckB) that differ only in whether they use the functions that come with MooseX :: AttributeHelpers . The getters created by Moose for DeckBare not what I expected. Is this a mistake or I don’t understand how MooseX :: AttributeHelpers and MooseX :: FollowPBP should interact?

My workaround for this was to avoid using an argument isin such situations and instead declare readerand writeras needed.

use strict;
use warnings;

my %moose_args = (
    isa     => 'ArrayRef[Str]',
    is      => 'ro',
    default => sub {[]},
);

my %moose_attr_helper_args = (
    metaclass => 'Collection::Array',
    provides => {
        elements => 'get_all_cards',
    },
);

package DeckA;
use Moose;
use MooseX::FollowPBP;
use MooseX::AttributeHelpers;
has 'cards' => (%moose_args);

package DeckB;
use Moose;
use MooseX::FollowPBP;
use MooseX::AttributeHelpers;
has 'cards' => (%moose_args, %moose_attr_helper_args);

package main;
for my $class (qw(DeckA DeckB)){
    my $deck = $class->new;
    print "\n$class\n";
    for my $method ( qw(cards get_cards get_all_cards) ){
        print "$method: ", $deck->can($method) ? 'yes' : 'no', "\n";
    }
}

Output:

DeckA
cards: no
get_cards: yes
get_all_cards: no

DeckB
cards: yes          # Not what I expected.
get_cards: no       # Not what I expected.
get_all_cards: yes
+3
source share
2

, MX:: AH.

Moose API. (, ), MX:: FollowPBP.

+6

, FM .

, "" , :

MooseX:: AttributeHelpers "" Moose. MooseX:: FollowPBP, .

. Moose:: Meta:: Attribute:: Native.

+1

Source: https://habr.com/ru/post/1718304/


All Articles