On Sat, 30 Dec 2023 21:26:33 +0100 (CET)
"Smylers " via perl5-porters <
perl5-...@perl.org> wrote:
> > + $callerpkg //= meta::get_package( $caller );
> > +
> > + $on ? $callerpkg->add_symbol( '&'.$_ => \&{$_} )
>
> With get_package() returning an object, it's effectively a
> constructor — but it doesn't really look like one. Elsewhere in Perl,
> constructors are mostly class methods, on the class of the object
> you'll get back. And the ones that aren't are generally imported
> ‘shortcut’ functions (such as path in Path::Tiny), which don't
> specify a namespace when being used. Calling meta::get_package() as a
> function is a slightly awkward combination of the two.
>
> Apologies for the bikeshedding, especially when you've obviously
> thought about this way more than I have (so please feel free to
> completely ignore me), but might it seem more intuitive — and also
> less likely to make users question the syntax to use for constructors
> in completely unrelated classes — if it meta::get_package($name) were
> instead something like:
>
> meta::package->get($name)
>
> with the object returned being an instance of the meta::package class?
Yes; that's a reasonable thought. It's the way that
Object::Pad::MOP::Class works, for example. It didn't feel very "core
perlish", but that's very subjective. Perhaps it would be better as a
class constructor in that form, indeed.
I could add some alternative forms in that shape and see how each feels
to use in practice.
I should also add (that I forgot to add in documentation so far) that
the whole thing is very experimental anyway, so no promises about API
stability at this time. Now's a great time to experiment with what
might work and find the best shape.
> Then the subsections ‘Methods on Metapackages’, ‘Methods on
> Metasymbols’, and so on, could be ‘meta::package methods’,
> ‘meta::symbol’ methods, etc, which would probably be clearer, because
> the various classes would be explicit. Currently the docs mention
> that different types of objects can be returned, but doesn't say what
> packages those are in ... which seems a little ironic for a
> metaprogramming feature!
Mmmyes another entirely fair point there :)