Mailing List Archive

Class specification via :isa class attribute
Let's imagine that I wrote a module for importing packages. Among other
features it allows to alias long package name to something shorter. It
is realised as constant subrouine returning real package name.
Something like:

use package 'Foo::Bar/Bar';

/Bar part declares alias Bar for Foo::Bar. Now I can write Bar->new
instead of Foo::Bar->new. (I know that defining alias subroutines like
Bar can cause problems at a distance, that's why they are lexical by
default thanks to builtin::export_lexically.) It works because Perl
allows to specify class names in a few ways:

Foo::Bar->new;
'Foo::Bar'->new;
Foo::Bar::->new;
Bar->new; # Early defined subroutine

But the problem is that :isa class attribute of new OOP system accepts
only Foo::Bar::Baz form. I can't inherit using alias:

use feature 'class';
use package 'Foo::Bar::Baz/Baz';
class Foo::Baz :isa(Bar);

It dies:

Can't locate Bar.pm in @INC (you may need to install the Bar module) ...

It would be useful for me if above mentioned class specification forms
was supported by :isa attribute (and by similar attributes, :does comes
to mind). It also would be into line with the rest of the language. Is
it provisioned to do so?

--
Ivan Vorontsov <ivrntsv@yandex.ru>
Re: Class specification via :isa class attribute [ In reply to ]
[.Sorry. I changed the message while redacted but not everywhere.
Resending as it meant to be.]

Let's imagine that I wrote a module for importing packages. Among other
features it allows to alias long package name to something shorter. It
is realised as constant subrouine returning real package name.
Something like:

use package 'Foo::Bar/Bar';

/Bar part declares alias Bar for Foo::Bar. Now I can write Bar->new
instead of Foo::Bar->new. (I know that defining alias subroutines like
Bar can cause problems at a distance, that's why they are lexical by
default thanks to builtin::export_lexically.) It works because Perl
allows to specify class names in a few ways:

Foo::Bar->new;
'Foo::Bar'->new;
Foo::Bar::->new;
Bar->new; # Early defined subroutine

But the problem is that :isa class attribute of new OOP system accepts
only Foo::Bar form. I can't inherit using alias:

use feature 'class';
use package 'Foo::Bar/Bar';
class Foo::Baz :isa(Bar);

It dies:

Can't locate Bar.pm in @INC (you may need to install the Bar module) ...

It would be useful for me if above mentioned class specification forms
was supported by :isa attribute (and by similar attributes, :does comes
to mind). It also would be into line with the rest of the language. Is
it provisioned to do so?

--
Ivan Vorontsov <ivrntsv@yandex.ru>
Re: Class specification via :isa class attribute [ In reply to ]
On Mon, 26 Feb 2024 19:20:36 +0300 Ivan Vorontsov <ivrntsv@yandex.ru> wrote:

> It would be useful for me if above mentioned class specification forms
> was supported by :isa attribute (and by similar attributes, :does comes
> to mind). It also would be into line with the rest of the language. Is
> it provisioned to do so?

:does in the future of course.

--
Ivan Vorontsov <ivrntsv@yandex.ru>
Re: Class specification via :isa class attribute [ In reply to ]
On 26.02.24 17:20, Ivan Vorontsov wrote:
> [.Sorry. I changed the message while redacted but not everywhere.
> Resending as it meant to be.]
>
> Let's imagine that I wrote a module for importing packages. Among other
> features it allows to alias long package name to something shorter. It
> is realised as constant subrouine returning real package name.

Besides the point, but https://metacpan.org/pod/aliased exists. :-)
Re: Class specification via :isa class attribute [ In reply to ]
On Mon, 26 Feb 2024 19:37:15 +0100 Lukas Mai <lukasmai.403+p5p@gmail.com> wrote:

> On 26.02.24 17:20, Ivan Vorontsov wrote:
> > [.Sorry. I changed the message while redacted but not everywhere.
> > Resending as it meant to be.]
> >
> > Let's imagine that I wrote a module for importing packages. Among other
> > features it allows to alias long package name to something shorter. It
> > is realised as constant subrouine returning real package name.
>
> Besides the point, but https://metacpan.org/pod/aliased exists. :-)

Yeah. And Package namespace is taken. I scratch my itches with my
module. I don't think that I will publish it. It was brought to
illustrate the point.

--
Ivan Vorontsov <ivrntsv@yandex.ru>