(1) add method IO::Path.stemname; (2) expand method IO::Path.parts #5097
Class IO:Path currently has many methods for handling path name. The
I would like to see a new method named, say, stemname, which would be
# existing method: basename
# existing method: extension
# new method: stemname
# updated old method: parts
Isn't that what the word `basename` conveys too?
After all, the purpose of the well-known `basename` POSIX utility is to return the filename with its suffix stripped. It's just that it doesn't guess what you want to consider a suffix, so it strips nothing as an edge case when no suffix list is specified.
I'd thus consider the Perl 6 `.basename` method a misnomer, since its purpose is to always return the whole filename.
Ideally, Perl 6 would provide:
`.filename` -- whole filename
I suppose `.stemname` is a decent synonym for `.basename`, so a plan forward without much backwards compatibility breakage could be:
1) Introduce `.stemname` as this RFC suggests.
(Another candidate for deprecation would be `.dirname`, since AFAICT it's redundant with the much more clearly named .parent. And lets not even get into `.abspath` and `absolute` both existing, and the inconsistency of some routines returning paths as IO::Path and others returning paths as Str. Yeah, there's a lot of cleanup potential in the IO parts of the language...:P)
On Thu, 28 Jan 2016 10:45:04 -0800, tbrowder wrote:
Thanks for the suggestion, however, I'm going to reject this RFC.
You showed the most common example—a single part extension—but it has the same limitations as the old .extension method (e.g., I'd expect the "stemname" of "foo.tar.gz" to be "foo" not "foo.tar").
As of Rakudo 2017.04.2, you can use .extension method remove the extension, removing however many parts you want to remove, and you can then call .basename on the returned path to get the "stemname":