======================================================================
 Perl7::Handy ì¹í¸ ìí¸                         [KO] íêµ­ì´
======================================================================

[ 1. Installation ]

  ì¤ì¹:
    cpan Perl7::Handy

  ì¤í¬ë¦½í¸ìì ì¬ì©:
    use Perl7::Handy;

  í¨ê³¼ (Perl 5.010001 ì´ì):
    * use strict               -- ë³ì ì ì¸ ê°ì 
    * use warnings             -- ê²½ê³  íì±í
    * no bareword::filehandles -- open(FILE,...) íì ê¸ì§
    * no multidimensional      -- $hash{a,b} ìë®¬ë ì´ì ë¹íì±í
    * use feature qw(signatures)  (Perl 5.020+)
    * no feature qw(indirect)     (Perl 5.031009+)

  í¨ê³¼ (Perl 5.005_03 -- 5.008):
    * use strict
    * open/opendir/sysopen/pipe/socket/accept ìë ë³ì ìì±
    # socket() 은 실패해도 autodie 하지 않음 (void context에서 false 반환)
    * tie ê¸°ë° $; í¸ë© (ë¤ì°¨ì ë°°ì´ ìë®¬ë ì´ì ìµì )

[ 2. open() -- autovivification ]

  my $fh;
  open($fh, "< file.txt");   # ì½ê¸°
  open($fh, "> file.txt");   # ì°ê¸° (ë®ì´ì°ê¸°)
  open($fh, ">> file.txt");  # ì¶ê°
  open($fh, "+< file.txt");  # ì½ê¸°/ì°ê¸°
  while (my $line = readline($fh)) { ... }
  print $fh "text\n";
  close($fh);

  # ë² ì´ìë í¸ë¤ ê¸ì§ë¨:
  open(FILE, "< file.txt");   # dies: Use of bareword handle in open

[ 3. open() -- 3-arg ]

  my $fh;
  open($fh, '<',  "file.txt");   # ì½ê¸°
  open($fh, '>',  "file.txt");   # ì°ê¸° (ë®ì´ì°ê¸°)
  open($fh, '>>', "file.txt");   # ì¶ê°
  open($fh, '+<', "file.txt");   # ì½ê¸°/ì°ê¸°
  open($fh, '+>', "file.txt");   # ì½ê¸°/ì°ê¸° (ë®ì´ì°ê¸°)
  open($fh, '-|', "cmd");        # ëªë ¹ íì´íìì ì½ê¸°
  open($fh, '|-', "cmd");        # ëªë ¹ íì´íë¡ ì°ê¸°

[ 4. opendir() / sysopen() ]

  my $dh;
  opendir($dh, "/path/to/dir");
  while (my $e = readdir($dh)) {
      next if $e eq '.' or $e eq '..';
      print "$e\n";
  }
  closedir($dh);

  use Fcntl qw(O_RDONLY O_WRONLY O_CREAT O_TRUNC);
  my $fh;
  sysopen($fh, "file.txt", O_RDONLY);
  sysopen($fh, "file.txt", O_WRONLY | O_CREAT | O_TRUNC, 0644);

[ 5. pipe() ]

  my($reader, $writer);
  pipe($reader, $writer);
  if (my $pid = fork()) {
      close($writer);
      while (my $line = readline($reader)) { print $line }
      close($reader);
  } else {
      close($reader);
      print $writer "ìì íë¡ì¸ì¤ìì ìëíì¸ì\n";
      close($writer);
      exit 0;
  }

[ 6. socket() / accept() ]

  use Socket qw(AF_INET SOCK_STREAM sockaddr_in inet_aton);
  my $server;
  socket($server, AF_INET, SOCK_STREAM, 0);
  # 주의: socket() 은 실패해도 autodie 하지 않음. 반환값을 명시적으로 확인할 것.
  my $client;
  accept($client, $server);

[ 7. no bareword::filehandles ]

  # ë² ì´ìë í¸ë¤ ê¸ì§ë¨:
  open(FILE, "< file.txt");    # error: Bareword filehandle
  print FILE "hello\n";        # error: Bareword filehandle

  # ë ìì»¬ ë³ì ì¬ì©:
  my $fh;
  open($fh, "< file.txt");
  print $fh "hello\n";
  close($fh);

[ 8. no multidimensional ]

  # ë¤ì°¨ì í´ì ìë®¬ë ì´ì ë¹íì±íë¨:
  my %h;
  $h{1,2} = "val";    # error: Use of multidimensional array emulation

  # ëªìì  í¤ ì¬ì©:
  $h{"$x,$y"} = "val";

[ 9. Signatures (Perl 5.020+) ]

  # ìëª ìë íì±í; ì¤íì  ê²½ê³  ìµì 
  use Perl7::Handy;

  sub greet($name) { return "Hello, $name!" }
  sub add($x, $y)  { return $x + $y }

[ 10. no indirect (Perl 5.031009+) ]

  # ê°ì  ê°ì²´ êµ¬ë¬¸ ë¹íì±íë¨:
  my $obj = new MyClass;   # error: indirect syntax

  # ì§ì  êµ¬ë¬¸ ì¬ì©:
  my $obj = MyClass->new;

[ 11. CVE-2016-1238 ]

  # Perl7::Handy ë ìì ì @INC ìì íì¬ ëë í ë¦¬ë¥¼ ì ê±°íë¤.
  # BEGIN { pop @INC if $INC[-1] eq '.' }

[ 12. ë²ì ë³ ê¸°ë¥ í¸íí ]

  Feature              5.005_03  5.006-009  5.010+  5.020+  5.031009+
  -------------------  --------  ---------  ------  ------  ---------
  strict               yes       yes        yes     yes     yes
  warnings             no        yes        yes     yes     yes
  autovivif. open()    yes       yes        yes*    yes*    yes*
  no bareword FH       emulated  emulated   yes     yes     yes
  no multidim.         tie       tie        yes     yes     yes
  signatures           no        no         no      yes     yes
  no indirect          no        no         no      no      yes

[ 13. Official resources ]

  Perl7::Handy (MetaCPAN):
    https://metacpan.org/dist/Perl7-Handy

  bareword::filehandles:
    https://metacpan.org/dist/bareword-filehandles

  INABA Hitoshi (ina) on CPAN:
    https://metacpan.org/author/INA

======================================================================
