http://www.perlmonks.org?node_id=329129


in reply to Confused about splitting program into multiple files.

"I cannot install this as a module on the system, I only have limited access to where I can put my files."

I would like to bring your attention to non-priviledged installations in case you didn't already know that you can install modules on your system. :)

(updated ... added paragraph)
Now then. As for exporting ... why do people think that exporting is easier to implement then OO? If you stick with OO methods (that is, you instantiate a class and use it's methods) then you never have to worry about cluttering namespace or getting the Export code correct. Besides, these days you can cheat big time with modules like Class::MethodMaker that "write the code for you." Observe:

my $dude = new Person; $dude->name('Spicoli'); $dude->age(20); print $dude->as_string, "\n"; package Person; use Class::MethodMaker new => 'new', get_set => [qw(name age)], ; sub as_string { my $self = shift; return $self->name . ' (' . $self->age . ')'; }
Much nicer. :)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re: Re: Confused about splitting program into multiple files.
by davido (Cardinal) on Feb 15, 2004 at 16:16 UTC
    Ok, here's a question though. What made you choose to

    use Class::MethodMaker;

    instead of

    use base Class::MethodMaker;

    or

    use Class::MethodMaker; our @ISA = qw/Class::MethodMaker/;

    In other words, when should you choose inheritance rather than simple use? The barometer that I've kind of adopted is if I want my object or class to behave as a parent class, inherit. It seems that Class::MethodMaker is one of those cases.

    Please forgive my continued novicity on this subject. ;)


    Dave

      Because i still forget from time to time that one should always "favor aggregation over inheritance." :)

      UPDATE:
      Or am i second guessing myself again? Yes ... never mind my reply, i thought you were referring to something else. (But the concept of aggregation vs. inheritance is still important.)

      My usage simply follows what is illustrated in the POD. There is some syntactical sugar involved, so i don't read into the "useage" too literally -- think of Class::MethodMaker as magic. :)

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)