======================================================================
 Perl7::Handy Ð¥ÑÑÑÑÐ°Ð³                        [MN] ÐÐ¾Ð½Ð³Ð¾Ð»
======================================================================

[ 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 autovivification
    # 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);

  # bareword handle ÑÐ°ÑÐ³Ð°Ð»Ð·Ð°Ð²:
  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 ]

  # bareword handle ÑÐ°ÑÐ³Ð°Ð»Ð·Ð°Ð²:
  open(FILE, "< file.txt");    # error: Bareword filehandle
  print FILE "hello\n";        # error: Bareword filehandle

  # lexical ÑÑÐ²ÑÑÐ°Ð³Ñ Ð°ÑÐ¸Ð³Ð»Ð°:
  my $fh;
  open($fh, "< file.txt");
  print $fh "hello\n";
  close($fh);

[ 8. no multidimensional ]

  # Ð¾Ð»Ð¾Ð½ ÑÑÐ¼Ð¶ÑÑÑÑ hash Ð´ÑÑÑÐ°Ð¹Ð»Ñ Ð¸Ð´ÑÐ²ÑÐ³Ò¯Ð¹:
  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

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