Path::Tiny を継承する

Path::Tiny - search.cpan.org

Path::Tiny には new という、いかにもオブジェクト指向的なコンストラクタのような名前のメソッドが定義されているのでいかにもオブジェクト指向的に継承できるように見えるが結論から言うと できない

sub new { shift; path(@_) }

Path-Tiny/Tiny.pm at 37c371dbd100d82968b57bafc52222463ceb53bd · dagolden/Path-Tiny · GitHub

This is just like C, but with method call overhead. (Why would you do that?)

とあるので、ドキュメントにある通りとも言える。

どうしても継承したい場合は再度 bless を呼べば上書きされる。

package My::Path;
use parent qw( Path::Tiny );

sub new {
  my ($class, $path) = @_;
  my $self = $class->SUPER::new($path);
  return bless $self, $class;
}