-1

I am using Perl to try to implement an example for the Message::Stack module from CPAN.

I get the error

Can't locate object method "new" via package "Message::Stack" at stack.pl line 3.

my $stack = Message::Stack->new;

$stack->add(Message::Stack::Message->new(
  msgid     => 'something_happened',
  level     => 'error',
  scope     => 'login_formm',
  subject   => 'username',
  text      => 'Something happened!'
));

# Or... for those that want to type less
$stack->add({
  msgid     => 'something_else_happened',
  level     => 'error',
  scope     => 'login_form',
  subject   => 'password',
  text      => 'Something else happened!'
});

# ...
my $errors = $stack->for_level('error');
# Or
my $login_form_errors = $stack->for_scope('login_form');
$login_form_errors->for_subject('username');
print "Username has ".$login_form_errors->count." errors.\n";

Please let me know which object I need to load.

Borodin
  • 126,100
  • 9
  • 70
  • 144
Vinod HC
  • 1,557
  • 5
  • 20
  • 38
  • Did you read the complete error? Didn't it tell you what you need to `load`? – devnull May 08 '13 at 09:46
  • 1
    did you `use Message::Stack;` ? – mirod May 08 '13 at 09:48
  • I get only the following error: Can't locate object method "new" via package "Message::Stack" at stack.pl line 5. – Vinod HC May 08 '13 at 09:49
  • Yea when I try use Message::Stack I get the error as Can't locate Message/Stack.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.14.2 /usr/local/share/perl/5.14.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.14 /usr/share/perl/5.14 /usr/local/lib/site_perl .) at stack.pl line 4. BEGIN failed--compilation aborted at stack.pl line 4. – Vinod HC May 08 '13 at 09:50
  • then you need to install the module. You can use the `cpan` tool on the command line. – amon May 08 '13 at 09:59

1 Answers1

2

I am sure that what the message actually says is

Can't locate object method "new" via package "Message::Stack" (perhaps you forgot to load "Message::Stack"?) at stack.pl line 5.

So, did you forget?

And later, when you actually try to load it using

use Message::Stack

and it tells you

Can't locate Message/Stack.pm in @INC

doesn't it occur to you that it's not found because it isn't there, and needs installing?

Borodin
  • 126,100
  • 9
  • 70
  • 144