Makes a lot of use of caller. This makes it pretty hard for somebody else to wrap your code if they want an extra layer of abstraction.

A better way of doing it is something like this:

sub import { my $me = shift; my $opts = ref($_[0]) ? shift : { for => scalar caller }; my %wanted = map { $_ => 1 } @_; *{ $opts->{for} . "::logf" } = $me->_generate_logf($opts) if $wanted +{logf}; *{ $opts->{for} . "::logw" } = $me->_generate_logw($opts) if $wanted +{logw}; ...; } sub _generate_logf { shift; my $opts = shift; return sub { my $msg = shift; my $log = _get_logger($opts->{for}, shift); return unless $log->is_fatal; $log->fatal($msg); die "\n"; } } ...;

Exporters like Exporter::Tiny and Sub::Exporter support this kind of pattern — generating subs to export which have been specialized for whatever class is importing them — more easily than Exporter.pm. This technique will not only help avoid reliance on caller, making it easier for people to wrap your module, but will also help you further down the line when you are looking at making it more configurable.

Also, you didn't use strict or use warnings in your module. (And there's at least one part which would fail under use strict and currently could cause an issue under very contrived circumstances.)


In reply to Re: Evaluation of my CPAN module by tobyink
in thread Evaluation of my CPAN module by nysus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.