Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Caching a default instance to avoid initializing it every time (with Moo)

by karlgoethebier (Monsignor)
on Feb 09, 2018 at 10:45 UTC ( #1208807=note: print w/replies, xml ) Need Help??


in reply to Re: Caching a default instance to avoid initializing it every time (with Moo)
in thread Caching a default instance to avoid initializing it every time (with Moo)

"...looks like a singleton...I don't know if Moo can do this..."

Probably this can be easily done with Role::Singleton by just saying with 'Role::Singleton';?

I never used this and stumbled over it by chance.

Best regards, Karl

«The Crux of the Biscuit is the Apostrophe»

perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Replies are listed 'Best First'.
Re^3: Caching a default instance to avoid initializing it every time (with Moo)
by Eily (Prior) on Feb 09, 2018 at 10:52 UTC

    You'd still have to write a wrapper if you want a single interface to sometimes provide a new instance, sometimes the singleton. But I like that this interface leaves the choice to the caller, you can either have a new instance, regardless of input, or the singleton when you know it can work.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1208807]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2018-06-25 14:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (127 votes). Check out past polls.

    Notices?