perl-pearl has asked for the wisdom of the Perl Monks concerning the following question:

Hello!

I am having trouble with the 'new' method. I get this error when I try to implement just the example from the documentation.

Can't locate object method "new" via package "Data::ICal::Entry::Event" (perhaps you forgot to load "Data::ICal::Entry::Event"?)

I have downloaded and installed the Data::ICal module and the modules it is dependent on. The Todo.pm module just has the annotations and no methods!

Thank you for any insight.

Replies are listed 'Best First'.
Re: Data::ICal::Entry::Todo->new();
by pg (Canon) on Oct 07, 2005 at 05:21 UTC
    "The Todo.pm module just has the annotations and no methods!"

    If you did get the right code, then you have misunderstood the code. Open the source code up, you see two things:

    1. The Todo module does have methods defined, for example: optional_unique_properties.
      sub optional_unique_properties { qw( class completed created description dtstamp dtstart geo last-modified location organizer percent-complete priority recurrence-id sequence status summary uid url due duration ); }

      If you do:

      use Data::Dumper; use strict; use Data::ICal::Entry::Todo; my $vtodo = Data::ICal::Entry::Todo->new(); print Dumper($vtodo->optional_unique_properties());

      You get the following, which makes sense.

      $VAR1 = 'class'; $VAR2 = 'completed'; $VAR3 = 'created'; $VAR4 = 'description'; $VAR5 = 'dtstamp'; $VAR6 = 'dtstart'; $VAR7 = 'geo'; $VAR8 = 'last-modified'; $VAR9 = 'location'; $VAR10 = 'organizer'; $VAR11 = 'percent-complete'; $VAR12 = 'priority'; $VAR13 = 'recurrence-id'; $VAR14 = 'sequence'; $VAR15 = 'status'; $VAR16 = 'summary'; $VAR17 = 'uid'; $VAR18 = 'url'; $VAR19 = 'due'; $VAR20 = 'duration';
    2. It is "true" that the Todo module does not have a new() method defined, however, it says:

      use base qw/Data::ICal::Entry/;

      So it inherits new() from its parent - Entry, which does have new():

      sub new { my $class = shift; my $self = { properties => {}, entries => [], }; bless $self, $class; return $self; }
      Thank you. I had included the appropriate modules but, did not realize that the method was inherited.
Re: Data::ICal::Entry::Todo->new();
by jbrugger (Parson) on Oct 07, 2005 at 04:37 UTC
    Hi perl-pearl,
    Could you please post some lines of code that genereate your error?
    Probably you forgor to use the use or require statement:
    #!/usr/bin/perl -w use strict; use Data::ICal::Entry::Event; my $vevent = Data::ICal::Entry::Event->new();


    "We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise." - Larry Wall.
Re: Data::ICal::Entry::Todo->new();
by EvanCarroll (Chaplain) on Oct 07, 2005 at 04:42 UTC
    Check to see if you have a new method:
    perl -MData::ICal::Entry::Event -le'print grep {m/Event.pm/} values %I +NC' | xargs egrep 'sub.+new'

    or something like that.


    Evan Carroll
    www.EvanCarroll.com