Hi!
Nice to see you.
I'm new to OOP Peal.
Let me ask you a silly question.

When I try to use 'use base', I encountered an problem.
I wrote this program;

--------------------------------------------------------------- Animal.pm
package Animal;
sub speak {
my $class = shift;
print "a $class goes ", $class->sound, "!\n";
}
sub AUTOLOAD {
my $class = shift;
print "AUTOLOAD: a $class goes ", $class->sound, "!\n";
}
1;

--------------------------------------------------------------- Mouse.pm
use strict subs;
package Mouse;
use base 'Animal';
sub sound { 'squek' };
1;

--------------------------------------------------------------- farm.pl
use Mouse;
Mouse->speak;

and it work fine.

 C:\Documents and Settings\jackm\usetest>farm.pl
 a Mouse goes squek!

but when I unquote the quote of
use base 'Animal';
like this
 use base Animal;
It would cause an error;

C:\Documents and Settings\jackm\usetest>farm.pl
Unknown error
Compilation failed in require at C:\Documents and
Settings\jackm\usetest\farm.pl line 1.
BEGIN failed--compilation aborted at C:\Documents and
Settings\jackm\usetest\farm.pl line 1.

use Animal is allowed, but is use base Animal not allowed?
FYI, if you remove use strict subs, it won't be an error.

but in the file farm.pl,
use Mouse;
works but
use 'Mouse'

would be syntax error.

In summary ...
 no strict sub
  use Mouse OK
  use 'Mouse' NG
   use base Animal OK
  use base 'Animal' OK
use strict sub
  use Mouse OK
  use 'Mouse' NG
   use base Animal NG
  use base 'Animal' OK

Please tell my why I need quote after use base while using strict subs.
Thank you very much in advance !
-- jackm

Reply via email to