Looks like a good first stab to me. Biggest gripe i have
is with the constructors, and it is not ironic that you would use a variable named $cargocult ;) - try this
instead:
sub new {
my $class = shift;
my $id = shift;
my $self = {
_ID => $id,
_FINALIZED => 0,
_EXPENSES => [],
_TOTAL => undef,
_COUNT => undef,
};
return bless $self, $class;
}
Get rid of that 'ref (proto)' malarky and
note that $id will already be undef if it is not specified.
Other than that, everything seems OK - i do have a list
of minor nitpicks though:
- in ExpenseReport::add_expense() -
$newexp->{_ID} = $#expenses + 1;
seems more intuitive as
$newexp->{_ID} = scalar @expenses;
- in ExpenseReport::save_file - get rid of the temp
variable and just use
local $Data::Dumper::Indent = 3;
You are doing that in ExpenseReport::finalize, so i
suspect this code was overlooked.
-
ExpenseReport::load_file() - try this instead
# open file
my $file = do {local $/; <REPORT>};
- I notice that you connect, disconnect, and reconnect
several times to the database - this may be desired
behavior, but consider opening a connection and saving it
as an attribute of the class, or as another class.
-
Inside ExpenseReport::finalized() and all of Expense's
methods - change those one line if's to:
$self->{$hiddenkey} = shift if @_;
Having said all of that, you should now take a look at
CPAN modules like
Class::Struct and
Class::MethodMaker. I think these modules will
help you design your classes by giving you an interface
to work with. Also - use POD! This is a must for any class.
Include a section with sample usage.
Over all, very good work. And good luck with the next
step. :)
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)
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.