MakeMe...uiltin(3pm)

πŸ“¦
version 1.01 Β· 5 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– NAME πŸ’–

okay so this is MakeMe...uiltin(3pm) from the User Contributed Perl Documentation, and the module is Class::MakeMethods::Template::StructBuiltin β€” it generates a wrapper around some builtin function. yes bestie, we're wrapping a builtin and giving it a by-name interface. iconic behavior, honestly ✨


🌸 SYNOPSIS 🌸

  use Class::MakeMethods::Template::StructBuiltin (
    -TargetClass => 'MyStat',
    builtin_isa => [
      '-{new_function}'=>'stat',
        qw/ dev ino mode nlink /
    ]
  );

✨ DESCRIPTION ✨

Takes a (core) function name, and an arrayref of return position names (we will call it pos_list). Creates:

  • new β€” calls the core func with any given arguments, stores the result in the instance.
  • x β€” for each member of pos_list, creates a method of the same name which gets/sets the nth member of the returned list, where n is the position of x in pos_list.
  • fields β€” returns pos_list, in the given order.
  • dump β€” returns a list item name, item value, in order.

🧚 Example Usage 🧚

  package Stat;

  use Class::MakeMethods::Template::StructBuiltin
    builtin_isa => [ '-{new_function}'=>'stat', qw/ dev ino mode nlink / ],

  package main;

  my $file = "$ENV{HOME}/.template";
  my $s = Stat->new($file);
  print "File $file has ", $s->nlink, " links\n";
bestie, two notes before you run off: πŸ‘€
  • (a) the new method does not check the return value of the function called β€” in the above example, if $file does not exist, you will silently get an empty object 😭
  • (b) if you really want the above example, see the core File::stat module.

but you get the idea, I hope 🫢


k bye bestie! this page is perl v5.36.0, dated 2022-10-13, and the manual is MakeMe...uiltin(3pm) β€” slay and stay iconic πŸ’…βœ¨

πŸ“¦ where this page comes from