perl-language-server icon indicating copy to clipboard operation
perl-language-server copied to clipboard

Support for "has" attributes

Open mbuc82 opened this issue 1 year ago • 1 comments

Hello,

it would be great, if PLS would support the "has" attribute definitions from the Moose/Moo/Mo implementations of Perl, to be usable in the outline part of VSCode.

Moose

has 'node' => (is => 'rw', isa => 'Any');
 
has 'children' => (
    is      => 'ro',
    isa     => 'ArrayRef',
    default => sub { [] }
);
 
has 'parent' => (
    is          => 'rw',
    isa         => 'Tree',
    weak_ref    => 1,
    handles     => {
        parent_node => 'node',
        siblings    => 'children',
    }
);

Moo

has taste => (
  is => 'ro',
);
 
has brand => (
  is  => 'ro',
  isa => sub {
    die "Only SWEET-TREATZ supported!" unless $_[0] eq 'SWEET-TREATZ'
  },
);
 
has pounds => (
  is  => 'rw',
  isa => sub { die "$_[0] is too much cat food!" unless $_[0] < 15 },
);

Mo

has name1 => ( default => sub { 'Joe' } );
has name2 => ( builder => 'name_builder' );
has name3 => ( coerce => sub {$_[0]} );
has name4 => ( is => 'ro' );
has name4 => ( required => 1 );

Apart from that, the step to Perl's Cor implementation would also be a bit smaller.

mbuc82 avatar Sep 06 '23 08:09 mbuc82

Thanks for the suggestion. You're right, there should be some handling for commonly used OO systems in Perl.

I'll probably wait until it's a bit more mature before working on feature 'class'

FractalBoy avatar Sep 06 '23 11:09 FractalBoy