develooper Front page | perl.perl5.porters | Postings from February 2013

[perl #116975] [PATCH] perlfunc require: fix example subroutine

Thread Previous | Thread Next
From:
David Golden
Date:
February 28, 2013 02:16
Subject:
[perl #116975] [PATCH] perlfunc require: fix example subroutine
Message ID:
rt-3.6.HEAD-31961-1362017789-385.116975-75-0@perl.org
# New Ticket Created by  David Golden 
# Please include the string:  [perl #116975]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=116975 >



The semantics of require are reasonably complex.  The perlfunc entry
gives an example saying "has semantics similar to the following".
Unfortunately, that example leaves out a lot, which could mislead people
who -- for whatever reason -- want to try to emulate CORE::require.

This patch makes the following changes to bring the "sub require" example
closer to the actual behavior of CORE::require.

- Loads the filename with the correct calling package

- Corrects the phrasing of the error message when a file is not found

- Uses croak to show that errors are issued from the caller's
  perspective

- Shows (crudly) how to check if a version number has been passed as an
  argument instead of a filename

Things that are omitted:

- The core parses for version numbers in a way that distinguishes
  numbers from strings: C<< require 6 >> is not the same as
  C<< require "6" >>. A pure perl require can't do that, so I
  ignore that distinction and treat anything that looks like a version
  as a version

- There is no localization of %^H, as I'm led to believe this is
  unnecessary since Perl 5.12
---
 pod/perlfunc.pod |   28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About