kenahoo/Path-Class — pull request #36 by bpj (2014-12-05 13:45:29+00:00)
Title: Methods to get filename without extension, extension without filename etc.

Ken, we talked about this over email a long while ago.

This is my first pull request ever, so please bear with me if I'm doing it all wrong!

This adds methods for:

* `stem`: getting the filename (basename) without the extension.

* `suffix`/`extension`: getting the extension without the filename or directories.

* `with_suffix`/`with_extension`: getting the original directory and filename with another suffix.

* `basefile`: getting the basename as a Path::Class::File object.

We discussed using the linguistic terms 'stem' and 'suffix' on email.
I added aliases with 'extension' as well.

`suffix` returns the extension without a dot if there was a dot and an extension,
an empty string if there was a dot but no extension, and
undef if there was neither a dot nor an extension.
This is of course a side effect of using `my($suffix) = $file->basename =~ /\.([^.]*)?\z/;`
to get the suffix, but I think it may actually be useful, so I didn't 'normalize' the undef to an empty string.

`with_suffix` was added because it does the right thing regardless of whether you pass the new suffix with or without a leading dot.
Also unlike `$file->dir->file( $file->stem . ".newsuffix" )` it doesn't prepend a dot for the current directory if `$file` doesn't have any directory, which IMO is the Right Thing.

`basefile` was added so that you can do this without worrying whether the new suffix has a leading dot or not:

$some_dir->file( $some_file->basefile->with_suffix($some_suffix) )

I hope you find them all useful! I'm dealing programmatically with markdown/html or code/documentation etc. files having or meant to have the same stem+/-dir on a regular basis, and I don't think I'm the only one.

/bpj