Refactoring is less about making the code smaller than it is making the code more supportable. Usually the two go together, but not always. If you misplace these goals, you end up with smaller, less supportable code.
Both of your routines are succinct. The only refactoring I see that doesn't significantly reduce readability would be to add something like
Then you can rewrite the error handling to $o->LOGifError($tree, $@);sub LOGifError { my ($o, $what, $err) = @_; $o->LOG('error', "$what: $error") if $error; }
Or, if you want to "remove" two duplicate lines from each routine without adding a new method, rewrite
to $o->LOG('error', "$tree: $@") if $@; This latter rewrite is what I'd do.if ($@) { $o->LOG('error', "$tree: $@"); }
In reply to Re: My first thought was to build a macro... was I right?
by dws
in thread My first thought was to build a macro... was I right?
by princepawn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |