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
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');
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
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
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 @_;
}
foreach my $thrnum (1..10) {
- new Thread \&tester, $thrnum;
+ Thread->new(\&tester, $thrnum);
}
package Foo;