]> git.vpit.fr Git - perl/modules/indirect.git/blobdiff - lib/indirect.pm
Make the default error message public
[perl/modules/indirect.git] / lib / indirect.pm
index 9edc23ef2b7ac0f0d5473cd91b221121196d304d..53dc846c35692076b047854e0aafa6f41e031276 100644 (file)
@@ -11,13 +11,13 @@ indirect - Lexically warn about using the indirect object syntax.
 
 =head1 VERSION
 
-Version 0.13
+Version 0.15
 
 =cut
 
 our $VERSION;
 BEGIN {
- $VERSION = '0.13';
+ $VERSION = '0.15';
 }
 
 =head1 SYNOPSIS
@@ -29,8 +29,8 @@ BEGIN {
      use indirect;
      my $y = new Pear; # ok
      {
-      no indirect hook => sub { die "You really wanted $_[0]\->$_[1]" };
-      my $z = new Pineapple 'fresh'; # croaks 'You really wanted Pineapple->new'
+      no indirect hook => sub { die "You really wanted $_[0]\->$_[1] at $_[2]:$_[3]" };
+      my $z = new Pineapple 'fresh'; # croaks 'You really wanted Pineapple->new at blurp.pm:13'
      }
     }
     no indirect ':fatal';
@@ -86,10 +86,6 @@ Otherwise, a warning will be emitted for each indirect construct.
 
 =cut
 
-my $msg = sub {
- "Indirect call of method \"$_[1]\" on object \"$_[0]\" at $_[2] line $_[3].\n"
-};
-
 sub unimport {
  shift;
 
@@ -99,11 +95,11 @@ sub unimport {
   if ($arg eq 'hook') {
    $hook = shift;
   } elsif ($arg eq ':fatal') {
-   $hook = sub { die $msg->(@_) };
+   $hook = sub { die msg(@_) };
   }
   last if $hook;
  }
- $hook = sub { warn $msg->(@_) } unless defined $hook;
+ $hook = sub { warn msg(@_) } unless defined $hook;
 
  $^H |= 0x00020000;
  $^H{+(__PACKAGE__)} = _tag($hook);
@@ -122,14 +118,28 @@ sub import {
  ();
 }
 
+=head1 FUNCTIONS
+
+=head2 C<msg $object, $method, $file, $line>
+
+Returns the default error message generated by C<indirect> when an invalid construct is reported.
+
+=cut
+
+sub msg {
+ "Indirect call of method \"$_[1]\" on object \"$_[0]\" at $_[2] line $_[3].\n"
+};
+
 =head1 CONSTANTS
 
 =head2 C<I_THREADSAFE>
 
-True iff the module could have been built when thread-safety features.
+True iff the module could have been built with thread-safety features enabled.
 
 =head1 CAVEATS
 
+The implementation was tweaked to work around several limitations of vanilla C<perl> pragmas : it's thread safe, and doesn't suffer from a C<perl 5.8.x-5.10.0> bug that causes all pragmas to propagate into C<require>d scopes.
+
 C<meth $obj> (no semicolon) at the end of a file won't be seen as an indirect object syntax, although it will as soon as there is another token before the end (as in C<meth $obj;> or C<meth $obj 1>).
 
 With 5.8 perls, the pragma does not propagate into C<eval STRING>.