I'm currently working on a script to manage my sites news/content and need a perfect OOP strategy to use. The script is going to have a whole bunch of parts to it like actual news posting, category management, user management, static page management (like editing of index.html thru the script), etc.. so I need an OO strategy that will keep the script moving fast with more then 10 000 lines of code and make it still easy to expand down the road.
I was thinking about just doing the parts something like:
package MyScript::Categories;
sub MainPage { ...main categories page... }
sub Add { ...add categories page... }
..etc..
And then accessing category-related subs like
MyScript::Categories::Add, etc. but I've noticed it's rather a pain to do it that way. So then I thought of doing something like:
my $ms = new MyScript; # this would go up at the top
package MyScript;
sub new {
my $class = shift;
our $library = new MyScript::Library;
our $reviews = new MyScript::Reviews;
bless {}, $class;
}
package MyScript::Library;
sub new {
my $class = shift;
bless {}, $class;
}
# all library subs go here
package MyScript::Reviews;
sub new {
my $class = shift;
bless {}, $class;
}
# all subs related to reviews go here
Then I was thinking I could access my library subs through $library and review-related subs through $reviews anywhere in the script.
I'm not sure how either of the two OO strategies will handle with lots of code and such so I was hoping my fellow monks could give me some suggestions. These two designs might even be too poor to use in the long run so please, please point me in the right direction :)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.