Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
PATH::TINY 
Chiba.pm #5 / @waniji
߅Ãu 
@waniji 
´–Ï´£È§ò·Ê¡ 
VimsPerl„PrŠe
PATH::TINYt{ 
Ô £êìfá·ä–ê 
Path::ClasszTinyh 
File::Spec, File::Copy, File::Temp, File::Path, File::statvuž 
žoríR{vX|_zá·...
_Ÿv_tXcaŠe 
my $file = path("/home/waniji/memo.txt"); 
# ファイル名のみ表示 
say $file->basename; 
# ファイルに書き込み 
my $fh = $file->ope...
Æ¢ë®ÇéAzÔ £êDžª¥òÇ 
my $file = path(/home/waniji/); 
my $iterator = $file-iterator( { recurse = 1 } ); 
while( my $object ...
Po}P/^•˜— 
# /home/waniji/chibapm/memo.txt に aaa という文字列を書き込み 
my $file = path(/home/waniji/memo.txt); 
$file-parent-child(...
PATH::CLASStzঠ
ŸaP 
íP 
1Ô £ê 
UTF-8Jzà¼ÂÈXJa˜rP— 
Unix or Windows z‹”f;Ë
ØòÀݖ®(Ô £êw„YŸsg) 
my $path = /home/waniji/hoge.txt; 
cmpthese( 10000, { 
'Path::Tiny' = sub { 
my $file = path($path); ...
ØòÀݖ®(Æ¢ë®ÇéAzÔ £êžª¥òÇ) 
my $path = /home/waniji/temp; 
cmpthese( 100, { 
'Path::Tiny' = sub { 
my $dir = path($path); 
...
UTF-8zÔ £êžopencr‹— 
# Path::Class 
my $fh = $file-open(':encoding(UTF-8)') or die can't open $file: $!; 
# Path::Tiny 
my...
PATH::TINYsÎÝok_t
얪êW•NFSwÔ £êž¤” 
my $file = path(/home/waniji/memo.txt); 
$file-move(/nfs/memo.txt); 
ŒŒ 
¾{±¿z¶{½ 
‹Y^Y^Y^Y^Y‹
Path::Tinyzmove{ÆósrenamežžJcrP—k| £v 
—Ô £ê¶¸Åßw¤”e—_t{cavP} 
sub move { 
my ( $self, $dst ) = @_; 
return rename( $self...
PCŽ 
use File::Copy 'move'; 
move $file, /nfs/memo.txt;
Št 
6q
Upcoming SlideShare
Loading in …5
×

Path::Tiny

2,452 views

Published on

Chiba.pm #5 LT

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Path::Tiny

  1. 1. PATH::TINY Chiba.pm #5 / @waniji
  2. 2. ߅Ãu @waniji ´–Ï´£È§ò·Ê¡ VimsPerl„PrŠe
  3. 3. PATH::TINYt{ Ô £êìfá·ä–ê Path::ClasszTinyh File::Spec, File::Copy, File::Temp, File::Path, File::statvuž žoríR{vX|_zá·ä–ê1pslPkPca Še David Golden·XAuthor
  4. 4. _Ÿv_tXcaŠe my $file = path("/home/waniji/memo.txt"); # ファイル名のみ表示 say $file->basename; # ファイルに書き込み my $fh = $file->openw; $fh->print("chiba.pm") # ファイルの内容をすべて読み込み my $data = $file->slurp; # ファイルを削除 $file->remove; # 一時ファイルを作成 my $temp = Path::Tiny->tempfile;
  5. 5. Æ¢ë®ÇéAzÔ £êDžª¥òÇ my $file = path(/home/waniji/); my $iterator = $file-iterator( { recurse = 1 } ); while( my $object = $iterator-() ) { $count++ if $object-is_file; }
  6. 6. Po}P/^•˜— # /home/waniji/chibapm/memo.txt に aaa という文字列を書き込み my $file = path(/home/waniji/memo.txt); $file-parent-child(chibapm, memo.txt)-touchpath-openw-print(aaa);
  7. 7. PATH::CLASStz‡¶ ŸaP íP 1Ô £ê UTF-8Jzà¼ÂÈXJa˜rP— Unix or Windows z‹”f;Ë
  8. 8. ØòÀݖ®(Ô £êw„YŸsg) my $path = /home/waniji/hoge.txt; cmpthese( 10000, { 'Path::Tiny' = sub { my $file = path($path); $file-openw-print(aaa); $file-remove; }, 'Path::Class' = sub { my $file = file($path); $file-openw-print(aaa); $file-remove; }, }); Rate Path::Class Path::Tiny Path::Class 1862/s -- -29% Path::Tiny 2632/s 41% --
  9. 9. ØòÀݖ®(Æ¢ë®ÇéAzÔ £êžª¥òÇ) my $path = /home/waniji/temp; cmpthese( 100, { 'Path::Tiny' = sub { my $dir = path($path); my $iterator = $dir-iterator( { recurse = 1 } ); my $count; while( my $object = $iterator-() ) { $count++ if $object-is_file; } }, 'Path::Class' = sub { my $dir = dir($path); my $count; $dir-recurse( callback = sub { my $object = shift; $count++ if -f $object; }); }, }); Rate Path::Class Path::Tiny Path::Class 10.7/s -- -67% Path::Tiny 32.1/s 200% --
  10. 10. UTF-8zÔ £êžopencr‹— # Path::Class my $fh = $file-open(':encoding(UTF-8)') or die can't open $file: $!; # Path::Tiny my $fh = $file-openr_utf8;
  11. 11. PATH::TINYsÎÝok_t
  12. 12. 얪êW•NFSwÔ £êž¤” my $file = path(/home/waniji/memo.txt); $file-move(/nfs/memo.txt); ŒŒ ¾{±¿z¶{½ ‹Y^Y^Y^Y^Y‹
  13. 13. Path::Tinyzmove{ÆósrenamežžJcrP—k| £v —Ô £ê¶¸Åßw¤”e—_t{cavP} sub move { my ( $self, $dst ) = @_; return rename( $self-[PATH], $dst ) || $self-_throw( 'rename', $self-[PATH] . ' - '$dst' ); }
  14. 14. PCŽ use File::Copy 'move'; move $file, /nfs/memo.txt;
  15. 15. Št 6q

×