[PPC0022] - naming convention for exceptional vs. undef-returning methods
Nobody has claimed this yet.
- Dominant language
- Perl
- Stars
- 79
- Forks
- 28
- PR merge metrics
- No merged PRs in 30d
Description
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');
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading issue #44 and the referenced Object::Pad::MOP::Class try_for_class documentation. Compare the proposed get_/can_ and get_/try_get_ naming across both object and constructor-style APIs. Done means the naming convention and its behavior are decided and recorded in the PPC documentation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- perl
- Domain
- documentation
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100