<div class="gmail_extra">I'm trying to allow someone to set up a class B as a subclass of class A::Base::Class using an anonymous callback sub which isolates the configuration methods and keeps them out of both A::Base::Class and B in order to keep the namespace clear, but doesn't require the person using class A::Base::Class to know that all the configuration actually happens in A::Base::Class::ConfigurationSubclass (and keep said person from having to type `my ($x) = A::Base::Class::ConfigurationSubclass::config_this(42); A::Base::Class::ConfigurationSubclass::config_that($x + 5);`).</div>

<div class="gmail_extra"><br></div><div class="gmail_extra">Ultimately, if the programmer knew that `A::Base::Class::ConfigurationSubclass` was the direct way to configure their package, and didn't mind all the extra typing and the damage to the : key, he or she could do it, and the world wouldn't stop (this is Perl after all, I think it's in the contract somewhere that we have to provide at least two methods to achieve the same result). However, for his or her own sanity, `__PACKAGE__->configure(sub { my ($x) = config_this(42); config_that($x + 5); });` is also a possibility.</div>

<div class="gmail_extra"><br></div><div class="gmail_extra">Ultimately, the way I've rewritten the file in (<a href="https://gist.github.com/2499830#file_crazier.pl">https://gist.github.com/2499830#file_crazier.pl</a>) utilizing some hints from a CPAN Macro module I found per Alan's suggestion (localizing exported method calls to the aforementioned B class), has some known caveats (a sub named A::Base::Class::ConfigurationSubclass::config_this's existence would clobber any value of $B::config_this, @B::config_this, etc. during the call to configure(), for instance). I think they're probably livable though. Solving the one I mentioned isn't impossible but it comes with what I think is an unreasonable speed penalty. There are probably others, but nothing significant I've thought of yet.</div>

<div class="gmail_extra"><br></div><div class="gmail_extra">That being said, I don't think I've seen Perl modules configured this way in the past, and if it's because people have assessed it as a known possibility and discounted it as completely wrong-headed, I'm still relatively fresh in the process of writing the module that'd use it, and I can probably be talked back off the ledge if there are good reasons not to do it.</div>

<div class="gmail_extra"><br></div><div class="gmail_extra">--Stephen</div><div class="gmail_extra"><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Apr 26, 2012 at 12:44 PM, John SJ Anderson <span dir="ltr"><<a href="mailto:genehack@genehack.org" target="_blank">genehack@genehack.org</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
                <div><span style="color:rgb(160,160,168)">On Thursday, April 26, 2012 at 10:24 AM, Stephen Belcher wrote:</span></div>
                <blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-left:0px;padding-left:10px">
                    <span><div><div>Hi all,<div><br></div><div>I'm wondering if anyone has an answer to this? <a href="https://gist.github.com/2499830" target="_blank">https://gist.github.com/2499830</a></div><div><br>

</div></div></div></span></blockquote></div><div>Looking at the gist, and specifically at the last section of it, I'm wondering why you can't just use the fully specified method name. I.e., instead of</div><div><br>

</div><div><pre style="padding-right:0px;padding-left:0px;padding-top:0px;text-indent:0px;letter-spacing:normal;text-align:left;font-variant:normal;font-style:normal;margin-bottom:0px;font-weight:normal;padding-bottom:0px;margin-right:0px;line-height:1.4em;text-transform:none;margin-left:0px;margin-top:0px;word-spacing:0px">

<div style="font-family:'Bitstream Vera Sans Mono',Courier,monospace;font-size:12px;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:1em;line-height:1.4em">

    <span style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;line-height:1.4em;font-weight:bold">sub </span><span style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;line-height:1.4em;color:rgb(153,0,0);font-weight:bold">configure</span> <span style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;line-height:1.4em">{</span></div>

<div style="font-family:'Bitstream Vera Sans Mono',Courier,monospace;font-size:12px;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:1em;line-height:1.4em">

        <span style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;line-height:1.4em;font-weight:bold">my</span> <span style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;line-height:1.4em">(</span><span style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;line-height:1.4em;color:rgb(0,128,128)">$coderef</span><span style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;line-height:1.4em">)</span> <span style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;line-height:1.4em;font-weight:bold">=</span> <span style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;line-height:1.4em;font-weight:bold">sub </span><span style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;line-height:1.4em">{</span></div>

<div style="font-family:'Bitstream Vera Sans Mono',Courier,monospace;font-size:12px;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:1em;line-height:1.4em">

            <span style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;line-height:1.4em">hello</span><span style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;line-height:1.4em">;</span></div>

<div style="font-family:'Bitstream Vera Sans Mono',Courier,monospace;font-size:12px;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:1em;line-height:1.4em">

        <span style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;line-height:1.4em">};</span></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:1em;line-height:1.4em">

<font face="Helvetica"><br></font></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:1em;line-height:1.4em"><font face="Helvetica">do</font></div>

<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:1em;line-height:1.4em"><font face="Helvetica"><pre style="padding-right:0px;padding-left:0px;padding-top:0px;text-indent:0px;letter-spacing:normal;text-align:left;font-variant:normal;font-style:normal;margin-bottom:0px;font-weight:normal;padding-bottom:0px;line-height:1.4em;margin-right:0px;text-transform:none;font-size:12px;margin-left:0px;font-family:'Bitstream Vera Sans Mono',Courier,monospace;margin-top:0px;word-spacing:0px">

<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:1em;line-height:1.4em">    <span style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;line-height:1.4em;font-weight:bold">sub </span><span style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;line-height:1.4em;color:rgb(153,0,0);font-weight:bold">configure</span> <span style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;line-height:1.4em">{</span></div>

<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:1em;line-height:1.4em">        <span style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;line-height:1.4em;font-weight:bold">my</span> <span style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;line-height:1.4em">(</span><span style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;line-height:1.4em;color:rgb(0,128,128)">$coderef</span><span style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;line-height:1.4em">)</span> <span style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;line-height:1.4em;font-weight:bold">=</span> <span style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;line-height:1.4em;font-weight:bold">sub </span><span style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;line-height:1.4em">{</span></div>

<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:1em;line-height:1.4em">            PackageA::<span style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;line-height:1.4em">hello</span><span style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;line-height:1.4em">;</span></div>

<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:1em;line-height:1.4em">        <span style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;line-height:1.4em">};</span></div>

<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:1em;line-height:1.4em"><br style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;line-height:1.4em">

</div></pre></font></div></pre></div><div class="im"><div><br></div><div> </div><blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-left:0px;padding-left:10px"><span><div><div><div></div><div>Essentially, I want to create a coderef while in the scope of one package, and delay binding of the subroutine calls until the actual execution, which will happen in or relative to another package, meaning that the subroutines that eventually resolve will be the ones located in the second package, not the first. This is different from what normally happens in closures.</div>

</div></div></span></blockquote></div><div>It sounds like you have some problem you're trying to decide, and you have gotten onto this particular path of solving it, and it's not really the right solution. Perhaps you could explain what you're trying to achieve with this code? (Not the "call a method in packageB but use packageA's context for method resolution", but the problem you were working on solving _before_ you started on this…)</div>

<div><br></div><div> chrs,</div><div>john.</div><div><br></div><blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-left:0px;padding-left:10px">
                 
                 
                 
                 
                </blockquote>
                 
                <div>
                    <br>
                </div>
            <br>_______________________________________________<br>
Baltimore-pm mailing list<br>
<a href="mailto:Baltimore-pm@pm.org">Baltimore-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/baltimore-pm" target="_blank">http://mail.pm.org/mailman/listinfo/baltimore-pm</a><br></blockquote></div><br></div>