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)
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.