questions in bold and at end

oop technique, class attributes singleton stored in private (my ) %hash

Have you seen this technique before? Pros/Cons? Why not our %BIN / our %CACHE ?

my (%BIN, %CACHE); sub data { ... return $CACHE{$class} || undef } sub is_binary { keys %{_all($_[1])} ? !!$BIN{$_[1]}{$_[2]} : undef } ## later on inside Mojo::Loader my $all = $CACHE{$class} = {}; $all->{$name} = $name =~ s/\s*\(\s*base64\s*\)$// && ++$BIN{$class}{$name} ? b64_decode($data) : $data; ## later on outside Mojo::Loader my $same = Mojo::Loader->new->data('class'); $same = Mojo::Loader->new->data('class'); my $same_also = Mojo::Loader->new->data('class', 'file'); $same_also = Mojo::Loader->new->data('class')->{'file'};

Say I want to change the way Mojo::Loader works (in particular sub _all ), I can't monkey patch because I can't access %CACHE or %BIN, so if I do monkeypatch, then I have to keep my own %CACHE/%BIN

I can't subclass either (same reason and) because there are a few consumers of this singleton and they all use Mojo::Loader->new

Also, they all depend on the existing data structure (hoh) -- there is no api

So then I'm left subclassing the consumers if I'm interested in changing the loader...

I've got the feeling this loader should have been an instance/attribute/has-one Mojo::Cache, and/or called Mojo::Loader->singleton ( like http://p3rl.org/Mojo::IOLoop#singleton ) ... what do you think? ?

Hmm, ->data->set or data_set ??

my $the_loader = app()->loader || Mojo::Loader->singleton ; $the_loader->load( $module ); $the_loader->data->get( $module, $key ); $the_loader->data->set( $module, $key, $value ); $the_loader->data_get( $module, $key ); $the_loader->data_set( $module, $key, $value );

So the review, the questions are

Thanks you for your thoughts and typings


In reply to oop technique, class attributes singleton stored in private (my ) %hash by Anonymous Monk

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.