Skip to content

Instantly share code, notes, and snippets.

@kfly8
Created September 5, 2024 11:16
Show Gist options
  • Save kfly8/d35325efa2a0b14a390d85f7890dce9b to your computer and use it in GitHub Desktop.
Save kfly8/d35325efa2a0b14a390d85f7890dce9b to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use utf8;
use experimental qw(class);
package HogeMouse {
use Mouse;
has foo => (is => 'rw', isa => 'Int');
has bar => (is => 'rw', isa => 'Int');
sub hello {}
}
class HogeBuiltinClass {
field $foo :param :reader;
field $bar :param :reader;
method hello($msg) {}
}
package HgoeClassAccesorLite {
use Class::Accessor::Lite (
new => 1,
rw => [qw/foo bar/],
);
sub hello {}
}
# コメントのように補完される
{
my $h = HgoeClassAccesorLite->new(foo => 1, bar => 2);
$h-
# $h->hello Method
}
{
my $h2 = HogeMouse->new(foo => 1, bar => 2);
$h2-
# $h2->meta Method
# $h2->hello Method
# $h2->bar Field
# $h2->foo Field
}
{
my $h3 = HogeBuiltinClass->new(foo => 1, bar => 2);
$h3-
# $h3->bar Method
# $h3->foo Method
# $h3->hello Method
}
{
my $klass = 'HogeBuiltinClass';
my $h4 = $klass->new(foo => 1, bar => 2);
$h4-
# no completion
}
{
sub get_service {
my ($klass, %args) = @_;
require $klass;
$klass->new(%args);
}
my $h5 = get_service(HogeMouse => foo => 1, bar => 2)
$h5-
# no completion
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment