[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]

[PATCH] remove indirect method calls from documentation




These patches remove a number of occurances of indirect method calls from POD
(or in a few cases usage message).  In no case should the meaning of code be
altered.  I left a few cases in place where the indirect form was used to
demonstrate it.  My strategy for finding it was very dumb (mostly my eyeball
and some search) so there are sure to be more left.  This is just a quick first
pass.

-- 
rjbs
From 22aafdb3e1e2806788772ade2fb8e72050d5f6fc Mon Sep 17 00:00:00 2001
From: Ricardo SIGNES <rjbs@cpan.org>
Date: Tue, 20 Jan 2009 18:21:34 -0500
Subject: [PATCH 1/2] remove some indirect method calls, add a caveat

---
 pod/perlcall.pod     |    6 +++---
 pod/perlfunc.pod     |    2 +-
 pod/perlglossary.pod |    3 +++
 pod/perlothrtut.pod  |   18 +++++++++---------
 4 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/pod/perlcall.pod b/pod/perlcall.pod
index 08173d2..06f3aa3 100644
--- a/pod/perlcall.pod
+++ b/pod/perlcall.pod
@@ -1218,9 +1218,9 @@ virtual. The static method, C<PrintID>, prints out simply the class
 name and a version number. The virtual method, C<Display>, prints out a
 single element of the array.  Here is an all Perl example of using it.
 
-    $a = new Mine ('red', 'green', 'blue');
+    $a = Mine->new('red', 'green', 'blue');
     $a->Display(1);
-    PrintID Mine;
+    Mine->PrintID;
 
 will print
 
@@ -1277,7 +1277,7 @@ the C<PrintID> and C<Display> methods from C.
 
 So the methods C<PrintID> and C<Display> can be invoked like this
 
-    $a = new Mine ('red', 'green', 'blue');
+    $a = Mine->new('red', 'green', 'blue');
     call_Method($a, 'Display', 1);
     call_PrintID('Mine', 'PrintID');
 
diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod
index 8ba3243..c8d6695 100644
--- a/pod/perlfunc.pod
+++ b/pod/perlfunc.pod
@@ -4675,7 +4675,7 @@ into package C<main>.)  Here is a typical code layout:
     }
 
     # In the main program
-    push @INC, new Foo(...);
+    push @INC, Foo->new(...);
 
 Note that these hooks are also permitted to set the %INC entry
 corresponding to the files they have loaded. See L<perlvar/%INC>.
diff --git a/pod/perlglossary.pod b/pod/perlglossary.pod
index d22e2ac..f0240b0 100644
--- a/pod/perlglossary.pod
+++ b/pod/perlglossary.pod
@@ -1457,6 +1457,9 @@ invocant between the method and its arguments:
   give $gollum "Fisssssh!";
   give $gollum "Precious!";
 
+In modern Perl, calling methods this way is often considered bad practice and
+to be avoided.
+
 =item indirect object slot
 
 The syntactic position falling between a method call and its arguments
diff --git a/pod/perlothrtut.pod b/pod/perlothrtut.pod
index 3253097..67d64eb 100644
--- a/pod/perlothrtut.pod
+++ b/pod/perlothrtut.pod
@@ -607,10 +607,10 @@ this:
     sleep 10; 
     $DataQueue->enqueue(undef);
 
-You create the queue with new Thread::Queue.  Then you can add lists of
-scalars onto the end with enqueue(), and pop scalars off the front of
-it with dequeue().  A queue has no fixed size, and can grow as needed
-to hold everything pushed on to it.
+You create the queue with C<< Thread::Queue->new >>.  Then you can add
+lists of scalars onto the end with enqueue(), and pop scalars off the
+front of it with dequeue().  A queue has no fixed size, and can grow as
+needed to hold everything pushed on to it.
 
 If a queue is empty, dequeue() blocks until another thread enqueues
 something.  This makes queues ideal for event loops and other
@@ -740,10 +740,10 @@ it.  A more elaborate example looks like this:
 
     use Thread qw(yield); 
 
-    new Thread \&thread_sub, 1; 
-    new Thread \&thread_sub, 2; 
-    new Thread \&thread_sub, 3; 
-    new Thread \&thread_sub, 4;
+    Thread->new(\&thread_sub, 1);
+    Thread->new(\&thread_sub, 2);
+    Thread->new(\&thread_sub, 3);
+    Thread->new(\&thread_sub, 4);
 
     sub sync_sub :locked { 
         my $CallingThread = shift @_; 
@@ -790,7 +790,7 @@ method attribute indicates whether the subroutine is really a method.
     }
 
     foreach my $thrnum (1..10) { 
-        new Thread \&tester, $thrnum; 
+        Thread->new(\&tester, $thrnum); 
     }
 
     package Foo; 
-- 
1.6.1

From 3305263a3210a9b0c208ad7301221630f498bd78 Mon Sep 17 00:00:00 2001
From: Ricardo SIGNES <rjbs@cpan.org>
Date: Tue, 20 Jan 2009 18:32:17 -0500
Subject: [PATCH 2/2] now get non-dual lived code

---
 lib/Benchmark.pm     |    8 ++++----
 lib/DirHandle.pm     |    4 ++--
 lib/Dumpvalue.pm     |    4 ++--
 lib/FileHandle.pm    |    8 ++++----
 lib/I18N/Collate.pm  |    8 ++++----
 lib/SelectSaver.pm   |    6 +++---
 lib/Term/ReadLine.pm |    4 ++--
 lib/overload.pm      |   20 ++++++++++----------
 8 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/lib/Benchmark.pm b/lib/Benchmark.pm
index 7e744a6..19a0343 100644
--- a/lib/Benchmark.pm
+++ b/lib/Benchmark.pm
@@ -81,9 +81,9 @@ countit - see how many times a chunk of code runs in a given time
 Returns the current time.   Example:
 
     use Benchmark;
-    $t0 = new Benchmark;
+    $t0 = Benchmark->new;
     # ... your code here ...
-    $t1 = new Benchmark;
+    $t1 = Benchmark->new;
     $td = timediff($t1, $t0);
     print "the code took:",timestr($td),"\n";
 
@@ -91,9 +91,9 @@ Returns the current time.   Example:
 
 Enables or disable debugging by setting the C<$Benchmark::Debug> flag:
 
-    debug Benchmark 1;
+    Benchmark->debug(1);
     $t = timeit(10, ' 5 ** $Global ');
-    debug Benchmark 0;
+    Benchmark->debug(0);
 
 =item iters
 
diff --git a/lib/DirHandle.pm b/lib/DirHandle.pm
index 0bddec2..757bf4b 100644
--- a/lib/DirHandle.pm
+++ b/lib/DirHandle.pm
@@ -9,7 +9,7 @@ DirHandle - supply object methods for directory handles
 =head1 SYNOPSIS
 
     use DirHandle;
-    $d = new DirHandle ".";
+    $d = DirHandle->new(".");
     if (defined $d) {
         while (defined($_ = $d->read)) { something($_); }
         $d->rewind;
@@ -46,7 +46,7 @@ use Carp;
 use Symbol;
 
 sub new {
-    @_ >= 1 && @_ <= 2 or croak 'usage: new DirHandle [DIRNAME]';
+    @_ >= 1 && @_ <= 2 or croak 'usage: DirHandle->new( [DIRNAME] )';
     my $class = shift;
     my $dh = gensym;
     if (@_) {
diff --git a/lib/Dumpvalue.pm b/lib/Dumpvalue.pm
index f182297..d5d93c7 100644
--- a/lib/Dumpvalue.pm
+++ b/lib/Dumpvalue.pm
@@ -488,7 +488,7 @@ Dumpvalue - provides screen dump of Perl data.
 =head1 SYNOPSIS
 
   use Dumpvalue;
-  my $dumper = new Dumpvalue;
+  my $dumper = Dumpvalue->new;
   $dumper->set(globPrint => 1);
   $dumper->dumpValue(\*::);
   $dumper->dumpvars('main');
@@ -500,7 +500,7 @@ Dumpvalue - provides screen dump of Perl data.
 
 A new dumper is created by a call
 
-  $d = new Dumpvalue(option1 => value1, option2 => value2)
+  $d = Dumpvalue->new(option1 => value1, option2 => value2)
 
 Recognized options:
 
diff --git a/lib/FileHandle.pm b/lib/FileHandle.pm
index 6be2242..b609614 100644
--- a/lib/FileHandle.pm
+++ b/lib/FileHandle.pm
@@ -111,25 +111,25 @@ FileHandle - supply object methods for filehandles
 
     use FileHandle;
 
-    $fh = new FileHandle;
+    $fh = FileHandle->new;
     if ($fh->open("< file")) {
         print <$fh>;
         $fh->close;
     }
 
-    $fh = new FileHandle "> FOO";
+    $fh = FileHandle->new("> FOO");
     if (defined $fh) {
         print $fh "bar\n";
         $fh->close;
     }
 
-    $fh = new FileHandle "file", "r";
+    $fh = FileHandle->new("file", "r");
     if (defined $fh) {
         print <$fh>;
         undef $fh;       # automatically closes the file
     }
 
-    $fh = new FileHandle "file", O_WRONLY|O_APPEND;
+    $fh = FileHandle->new("file", O_WRONLY|O_APPEND);
     if (defined $fh) {
         print $fh "corge\n";
         undef $fh;       # automatically closes the file
diff --git a/lib/I18N/Collate.pm b/lib/I18N/Collate.pm
index 132b425..257390f 100644
--- a/lib/I18N/Collate.pm
+++ b/lib/I18N/Collate.pm
@@ -11,8 +11,8 @@ I18N::Collate - compare 8-bit scalar data according to the current locale
 
     use I18N::Collate;
     setlocale(LC_COLLATE, 'locale-of-your-choice'); 
-    $s1 = new I18N::Collate "scalar_data_1";
-    $s2 = new I18N::Collate "scalar_data_2";
+    $s1 = I18N::Collate->new("scalar_data_1");
+    $s2 = I18N::Collate->new("scalar_data_2");
 
 =head1 DESCRIPTION
 
@@ -81,8 +81,8 @@ European character set.
 #
 # Usage:	use I18N::Collate;
 #	        setlocale(LC_COLLATE, 'locale-of-your-choice'); # 4)
-#		$s1 = new I18N::Collate "scalar_data_1";
-#		$s2 = new I18N::Collate "scalar_data_2";
+#		$s1 = I18N::Collate->("scalar_data_1");
+#		$s2 = I18N::Collate->("scalar_data_2");
 #		
 #		now you can compare $s1 and $s2: $s1 le $s2
 #		to extract the data itself, you need to deref: $$s1
diff --git a/lib/SelectSaver.pm b/lib/SelectSaver.pm
index 1207b88..f0900a5 100644
--- a/lib/SelectSaver.pm
+++ b/lib/SelectSaver.pm
@@ -11,13 +11,13 @@ SelectSaver - save and restore selected file handle
     use SelectSaver;
 
     {
-       my $saver = new SelectSaver(FILEHANDLE);
+       my $saver = SelectSaver->new(FILEHANDLE);
        # FILEHANDLE is selected
     }
     # previous handle is selected
 
     {
-       my $saver = new SelectSaver;
+       my $saver = SelectSaver->new;
        # new handle may be selected, or not
     }
     # previous handle is selected
@@ -39,7 +39,7 @@ use Carp;
 use Symbol;
 
 sub new {
-    @_ >= 1 && @_ <= 2 or croak 'usage: new SelectSaver [FILEHANDLE]';
+    @_ >= 1 && @_ <= 2 or croak 'usage: SelectSaver->new( [FILEHANDLE] )';
     my $fh = select;
     my $self = bless \$fh, $_[0];
     select qualify($_[1], caller) if @_ > 1;
diff --git a/lib/Term/ReadLine.pm b/lib/Term/ReadLine.pm
index c1d1762..d251271 100644
--- a/lib/Term/ReadLine.pm
+++ b/lib/Term/ReadLine.pm
@@ -6,7 +6,7 @@ If no real package is found, substitutes stubs instead of basic functions.
 =head1 SYNOPSIS
 
   use Term::ReadLine;
-  my $term = new Term::ReadLine 'Simple Perl calc';
+  my $term = Term::ReadLine->new('Simple Perl calc');
   my $prompt = "Enter your arithmetic expression: ";
   my $OUT = $term->OUT || \*STDOUT;
   while ( defined ($_ = $term->readline($prompt)) ) {
@@ -26,7 +26,7 @@ CPAN (under the C<Term::ReadLine::*> namespace).
 
 All the supported functions should be called as methods, i.e., either as 
 
-  $term = new Term::ReadLine 'name';
+  $term = Term::ReadLine->new('name');
 
 or as 
 
diff --git a/lib/overload.pm b/lib/overload.pm
index ba0202d..587874b 100644
--- a/lib/overload.pm
+++ b/lib/overload.pm
@@ -194,7 +194,7 @@ overload - Package for overloading Perl operations
     ...
 
     package main;
-    $a = new SomeThing 57;
+    $a = SomeThing-new( 57 );
     $b=5+$a;
     ...
     if (overload::Overloaded $b) {...}
@@ -902,7 +902,7 @@ If some mutator methods are directly applied to the overloaded values,
 one may need to I<explicitly unlink> other values which references the
 same value:
 
-    $a = new Data 23;
+    $a = Data->new(23);
     ...
     $b = $a;		# $b is "linked" to $a
     ...
@@ -911,13 +911,13 @@ same value:
 
 Note that overloaded access makes this transparent:
 
-    $a = new Data 23;
+    $a = Data->new(23);
     $b = $a;		# $b is "linked" to $a
     $a += 4;		# would unlink $b automagically
 
 However, it would not make
 
-    $a = new Data 23;
+    $a = Data->new(23);
     $a = 4;		# Now $a is a plain 4, not 'Data'
 
 preserve "objectness" of $a.  But Perl I<has> a way to make assignments
@@ -947,7 +947,7 @@ Put this in F<two_face.pm> in your Perl library directory:
 Use it as follows:
 
   require two_face;
-  my $seven = new two_face ("vii", 7);
+  my $seven = two_face->new("vii", 7);
   printf "seven=$seven, seven=%d, eight=%d\n", $seven, $seven+1;
   print "seven contains `i'\n" if $seven =~ /i/;
 
@@ -994,7 +994,7 @@ array reference and a hash reference.
 
 Now one can access an object using both the array and hash syntax:
 
-  my $bar = new two_refs 3,4,5,6;
+  my $bar = two_refs->new(3,4,5,6);
   $bar->[2] = 11;
   $bar->{two} == 11 or die 'bad hash fetch';
 
@@ -1231,8 +1231,8 @@ explicit recursion in num()?  (Answer is at the end of this section.)
 Use this module like this:
 
   require symbolic;
-  my $iter = new symbolic 2;	# 16-gon
-  my $side = new symbolic 1;
+  my $iter = symbolic->new(2);	# 16-gon
+  my $side = symbolic->new(1);
   my $cnt = $iter;
 
   while ($cnt) {
@@ -1352,8 +1352,8 @@ To see it in action, add a method
 
 to the package C<symbolic>.  After this change one can do
 
-  my $a = new symbolic 3;
-  my $b = new symbolic 4;
+  my $a = symbolic->(3);
+  my $b = symbolic->(4);
   my $c = sqrt($a**2 + $b**2);
 
 and the numeric value of $c becomes 5.  However, after calling
-- 
1.6.1


Follow-Ups from:
Alex Vandiver <alexmv@MIT.EDU>
Vincent Pit <perl@profvince.com>

[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]