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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |