[Chicago-talk] undef and Moose types
sean at blanton.com
Fri Apr 29 09:38:13 PDT 2011
Yeah, the 'Maybe' works great, and thanks for pointing me to the doc.
My ssh_builder looks like your safe_ssh, not sure what you meant. I have one
&ssh_builder for all (86!) classes. If a new class wants an ssh connection,
it consumes the 'SSH' role with the ssh attribute populated by &ssh_builder.
I have one case where I'm connecting to a bunch of machines and if one
machine is offline I absolutely want the script to keep going to process the
other machines and not die. In other cases, I connect to one machine and if
it can't connect, then there is no point in continuing and go ahead and die.
(In fact, I'm frequently forking and threading off the connections in
parallel now, but that's besides the point - I want to reserve the right to
handle any exception elegantly.)
So in my case, the consuming class, instead of the builder, needs to decide
how to handle a bad ssh connection: die or handle it and propagate handling
up the class hierarchy. Therefore the builder via the attribute needs to
pass success or fail to the consuming class and not make it's own decision
to die. And, I want as much of the common code as possible and all of the
Net::SSH2 code to go into &ssh_builder.
Finally, I get a lot of benefit from using this within the lazy build
context. It simplifies use of ssh for the consuming class - just check to
see if it has a value of undef (thanks now to 'Maybe') and if not, start
using it. It provides great encapsulation and minimizes over all resources,
because the program may end before needing to create some or all of the
On Fri, Apr 29, 2011 at 8:37 AM, Andrew Rodland <andrew at cleverdomain.org>wrote:
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Chicago-talk