cmarcelo has asked for the wisdom of the Perl Monks concerning the following question:
Hello,
I'm trying to use Class::Accessor to make accessors in a package inside the same file that my main script is, but apparently doesn't work. I reduced to a simple case:
#!/usr/bin/env perl use strict; use warnings; my $a = A->new({ hi => 'oi' }); print $a->hello."\n"; print $a->hi."\n"; package A; use base qw(Class::Accessor); A->mk_accessors(qw(hi)); sub hello { return "hello"; }
When I split package A into A.pm (adding '1;' at the end and 'use A;' in the main script) it works fine.
Am I missing something? Does Class::Accessor expect some kind of processing that only happens when the package is in a separate file? Are there alternatives that work with this setup (packages and main script together)?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using Class::Accessor with packages in the same file as the main script
by cmarcelo (Scribe) on Mar 30, 2007 at 12:48 UTC | |
by betterworld (Curate) on Mar 30, 2007 at 13:03 UTC |