I'm getting the listed error when trying to run code. I started by looking at the previous answers to similar questions. This question gave the best info. It showed me how to look at the item being loaded.
Here is my directory tree:
Pagerduty/
Client.pm
Obj.pm
test/
- pagerduty_tester.pl
Here is what the tester currently looks like:
#!/usr/bin/env perl
use lib "../..";
use strict;
use warnings;
use YAML qw/LoadFile/;
use Pagerduty::Client;
use Pagerduty::Obj;
use Data::Dumper;
use constant TRUE => 1;
use constant FALSE => 0;
print($INC{"Pagerduty/Obj.pm"}, "\n");
my $settings = LoadFile("pagerduty.yml");
my $client = Pagerduty::Client->new($settings);
sub create_test_incident{
my $incident_params = define_test_incident();
my $incident = $client->create_incident( $incident_params );
}
sub define_test_incident{
{
service_key => "<omitted>",
description => "Test Incident",
details => {
detail1 => "Details blah",
detail2 => "more detail",
},
}
}
my $obj = define_test_incident();
# print Dumper($obj);
print Dumper( Pagerduty::Obj->new( $obj ) );
# print Dumper( create_test_incident() )
Here is Pagerduty::Obj
package Pageduty::Obj;
use strict;
use warnings;
use Data::Structure::Util qw/unbless/;
use constant TRUE => 1;
sub new{
my $class = shift;
my $self = shift;
# $self->{objCode} = lc($self->{objCode});
return bless $self, $class;
}
sub serialize{
my $self = shift;
unbless($self);
}
sub update_values{
my $self = shift;
my $changes = shift;
if($self->{changes}){
while(my ($key, $value) = each $changes){
$self->{changes}->{$key} = $value;
}
} else{
$self->{changes} = $changes;
}
}
TRUE;
Finally, when I run the code I get the following:
../../Pagerduty/Obj.pm
Can't locate object method "new" via package "Pagerduty::Obj" (perhaps you forgot to load "Pagerduty::Obj"?)
When I cat ../../Pagerduty/Obj.pm I get the code listed above. This code lives in a library I created. I put that library in the variable PERL5LIB. I have the 'use lib ../..' line because I want it work on any computer. I have been trying to figure out for the past 2 days why this code is not working. Any ideas?
The other class works accept not being able to create new Pagerduty::Obj with the same error message.