The original PPC doc suggested two sets of "fetch an element from a meta-package" methods, named "get_..." and "can_..." to reflect the difference between methods that throw exceptions and methods that return undef when the requested entity does not exist.
my $metasym = $metapkg->get_symbol($name); # throws if missing
my $metasym = $metapkg->can_symbol($name); # return undef if missing
My original inspiration for can_... came from Perl's own $pkg->can(...) which returns a coderef or undef. But perhaps it's not so great.
In addition, the API shape suggested by #44 leads to an alternative form of fetching metasymbols directly, by doing things like
my $metavar = meta::variable->get('$some::package::variable');
my $metavar = meta::variable->get($pkgname, $varname);
Under that style, using ->can would not work. Perahps instead take inspiration from https://metacpan.org/pod/Object::Pad::MOP::Class#try_for_class and use get_... vs try_get_...
my $metasym = $metapkg->get_symbol($name);
my $metasym = $metapkg->try_get_symbol($name);
That also works for the constructor-style ones:
my $metavar = meta::variable->get('$some::package::variable');
my $metavar = meta::variable->try_get('$some::package::variable');
The original PPC doc suggested two sets of "fetch an element from a meta-package" methods, named "get_..." and "can_..." to reflect the difference between methods that throw exceptions and methods that return
undefwhen the requested entity does not exist.My original inspiration for
can_...came from Perl's own$pkg->can(...)which returns a coderef or undef. But perhaps it's not so great.In addition, the API shape suggested by #44 leads to an alternative form of fetching metasymbols directly, by doing things like
Under that style, using
->canwould not work. Perahps instead take inspiration from https://metacpan.org/pod/Object::Pad::MOP::Class#try_for_class and useget_...vstry_get_...That also works for the constructor-style ones: