Hi Ron, On Sun, 4 Sep 2011 15:28:17 -0700 (PDT) Ron Weidner <xecro...@yahoo.com> wrote:
> I have a class named Widget in a file named Widget.pm. I have another class > named Table in a file called Table.pm. Table extends Widget. > > --- > > package Widget; > #file Widget.pm > > #insert a bunch of methods... > > --- > > package Table; > #file Table.pm > use Widget; > @ISA=("Widget"); > Here you can use http://search.cpan.org/dist/parent/ or maybe http://search.cpan.org/dist/base/ . (or just use Moose or friends). > #insert several methods here... > > 1; > > --- > > package Framework; > #file Framework.pm > use Widget; > use Table; > 1; > > --- > > What I was doing was adding "use Widget;" and "use Table;" to the top of the > program that uses these classes. But, because I expect this library of > classes to grow significantly I created a third .pm file called Framework. > Inside the Framework.pm I added the "use Widget;" and "use Table;" and now I > only "use Framework;" in my application. > Well, in your case, "use Framework;" will be equivalent to "use Table;" (but won't be if more classes are added.). > #!/usr/bin/perl > #test.pl > use strict; > use warnings; > use Framework; > > #This line of code seems replaceable by either > #of the next 2 commented lines > my $some_var_of_class_widget = new Widget(); > > #uncommented, the next line of code seems to work too... > #my $some_var_of_class_widget = Widget->new(); > > #uncommented, so does the next line of code > #my $some_var_of_class_widget = Widget->new; > > my $table = new Table(); > Don't use indirect object notation: http://www.modernperlbooks.com/mt/2009/08/the-problems-with-indirect-object-notation.html > #insert several tests here... > Why aren't you using Test::More and TAP? http://search.cpan.org/perldoc?Test::Tutorial > This was a guess that happened to work. My queston is if this is a common > solution to reducing the number of "use" lines? Well, generally what I did until now was make sure that each of my classes explicitly spelled all of its dependencies, so I knew everything would continue to work. Your solution seems fine, but may break if some of the modules export symbols (see http://search.cpan.org/dist/Sub-Exporter/ and http://search.cpan.org/dist/Exporter/ ), and you wish to import them as well. > Is there a better solution > that wouldn't cause the all classes to get compiled at runtime every time I > "use Framework;" especially since all applications that use the Framework may > not need the entire suite of classes contained in the framework? Well, I've also heard of Damian Conway's http://search.cpan.org/dist/Toolkit/ , but I was told it's buggy, and it may be too magical. I should note that you may be prematurely optimising here, so you shouldn't worry about getting a lot of code compiled, until you are sure it's the bottleneck: http://c2.com/cgi/wiki?PrematureOptimization Regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ My Public Domain Photos - http://www.flickr.com/photos/shlomif/ C++ is complex, complexifying and complexified. (With apologies to the Oxford English Dictionary). Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/