in reply to Re: Avoid run-time checking
in thread Avoid run-time checking

Hi Athanasius,

OO approach looks over-kill to me. since unpacking template is only a small part of parsing a record.

Refactoring this into two different classes would be creating more duplication of code. since the rest of logic is the same.(handling missing field, and what not..;)

Replies are listed 'Best First'.
Re^3: Avoid run-time checking
by Anonymous Monk on Sep 12, 2015 at 09:08 UTC

    Refactoring this into two different classes would be creating more duplication of code. since the rest of logic is the same.(handling missing field, and what not..;)

    So make 3 classes , they don't have to OO :) MyRecs; MyRecs::Big; MyRecs::Lil;

    sub MyRecs::foo { my( $ro, $sham, $bo ) = @_; die "sham must sham " if not $sham =~ /sham/i; ... } sub MyRecs::Lil::foo { MyRecs::foo( unpack "n3A*", ... ); } sub MyRecs::Big::foo { MyRecs::foo( unpack "v3A*", ... ); }