"Christopher L. Everett" <[EMAIL PROTECTED]> writes:

> Check these modules:
> 
> package simian;
> use fields qw (name);
> 
> use strict; #very important!
> use Apache;
> use Apache::Request;
> use Apache::Constants qw(:common);
> 
> sub new {
>   my $type = shift;
>   my class1 $self = fields::new(ref $type || $type);
       ^^^^^^
ITYM   simian

>   $self->{name} = 'Jane';
>   return $self->{name};     # error here
                ^^^^^^^^^

"new" should return a blessed reference ($self here); 
instead you are returning "Jane".  Any later attempts 
to dereference the result of "new" ( aka "Jane") will 
produce an error under strictures.

> You will get an error like the following:
> 
> Can't use string ("Exchange::MyAccount3") as a HASH ref while "strict
> refs" in use at /usr/local/lib/perl5/site_perl/MyApp/Framework3.pm line
> 245.
> 
> What the heck am I doing wrong?

Check line 245 in Framework3.pm ; if it tries to dereference a 
simian object constructed from your simian::new sub, then you'll 
get an error.

More free advice- "fields" are fairly unreliable in 5.005_03, 
especially regarding inherited object attributes.  (I don't know 
if they're more reliable in 5.6, since I don't view 5.6 as reliable 
enough itself :)

I'd recommend you take another approach, like Class::Contract 
or Tie::SecureHash instead.  See Conway's _Object Oriented Perl_ 
for details.


HTH
-- 
Joe Schaefer

Reply via email to