IO::Path::Parts — IO::Path의 부분들을 담는 컨테이너
IO::Path::Parts — IO::Path의 부분들을 담는 컨테이너
IO::Path의 특정 부분(볼륨, 디렉터리 이름, 기본 이름)만 따로 다루고 싶을 때 IO::Path::Parts를 써요. 이 객체는 IO::Path 객체의 부분들을 담는 컨테이너예요. 보통 IO::Path 객체에 .parts 메서드를 호출해 만들고, IO::Spec의 저수준 경로 조작 서브클래스 객체에서 .split 루틴을 호출해 만들 수도 있어요.
class IO::Path::Parts does Positional does Associative does Iterable { }
IO::Path의 부분은 다음 세 가지예요.
- 볼륨(volume) —
.volume참고 - 디렉터리 이름(dirname) —
.dirname참고 - 기본 이름(basename) —
.basename참고
본문
메서드 (Methods)
method new
method new(\volume, \dirname, \basename)
\volume, \dirname, \basename을 각각 볼륨·디렉터리 이름·기본 이름 부분으로 하는 새 IO::Path::Parts 객체를 만들어요.
attribute volume
읽기 전용. IO::Path::Parts 객체의 볼륨을 반환해요.
IO::Path::Parts.new('C:', '/some/dir', 'foo.txt').volume.say;
# OUTPUT: «C:»
attribute dirname
읽기 전용. IO::Path::Parts 객체의 디렉터리 이름 부분을 반환해요.
IO::Path::Parts.new('C:', '/some/dir', 'foo.txt').dirname.say;
# OUTPUT: «/some/dir»
attribute basename
읽기 전용. IO::Path::Parts 객체의 기본 이름 부분을 반환해요.
IO::Path::Parts.new('C:', '/some/dir', 'foo.txt').basename.say;
# OUTPUT: «foo.txt»
이전 구현 (Previous implementations)
Rakudo 2020.06 이전에는 IO::Path의 .parts 메서드가 Map을 반환했고, IO::Spec 서브클래스들의 .split 루틴은 Pair의 List를 반환했어요. IO::Path::Parts 클래스는 Positional, Associative, Iterable을 함으로써 이런 이전 구현들과의 호환성을 유지해요.
my $parts = IO::Path::Parts.new('C:', '/some/dir', 'foo.txt');
say $parts<volume>; # OUTPUT: «C:»
say $parts[0]; # OUTPUT: «volume => C:»
say $parts[0].^name; # OUTPUT: «Pair»
.say for $parts[];
# OUTPUT: «volume => C:dirname => /some/dirbasename => foo.txt»