Sub::ArgShortcut

Sub::ArgShortcut is a Perl module with writing functions that use default arguments.
Download

Sub::ArgShortcut Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Aristotle Pagaltzis
  • Publisher web site:
  • http://search.cpan.org/~aristotle/Sub-ArgShortcut-1.01/lib/Sub/ArgShortcut.pm

Sub::ArgShortcut Tags


Sub::ArgShortcut Description

Sub::ArgShortcut is a Perl module with writing functions that use default arguments. Sub::ArgShortcut is a Perl module with writing functions that use default arguments.SYNOPSIS use Sub::ArgShortcut::Attr; sub mychomp :ArgShortcut { chomp @_ } while ( ) { # make a chomped copy of $_ without modifying it my $chomped_line = mychomp; # or, modify $_ in place mychomp; # ... }This module encapsulates the logic required for functions that assume $_ as their argument when called with an empty argument list, and which modify their arguments in void context but return modified copies in any other context. You only need to write code which modifies the elements of @_ in-place.argshortcut(&)This function takes a code reference as input, wraps a function around it and returns a reference to that function. The code that is passed in should modify the values in @_ in whatever fashion desired. The function from the synopsis could therefore also be written like this: use Sub::ArgShortcut; my $mychomp = argshortcut { chomp @_ };This function is exported by default.Sub::ArgShortcut::Attr and :ArgShortcut - The attribute interfaceInstead of using argshortcut to wrap a code reference, you can use an Attribute::Handler-based interface to add Sub::ArgShortcut functionality to regular subs. Simply use Sub::Shortcut::Attr instead of Sub::Shortcut, then request its behaviour using the :ArgShortcut attribute on functions: sub mychomp :ArgShortcut { chomp @_ } my $mychomp = sub :ArgShortcut { chomp @_ }; Requirements: · Perl


Sub::ArgShortcut Related Software