<?xml version="1.0" encoding="windows-1252"?>
<node id="1014177" title="Re: is my api wrapper abstraction ok (is it perlish?)" created="2013-01-19 02:28:25" updated="2013-01-19 02:28:25">
<type id="11">
note</type>
<author id="757127">
tobyink</author>
<data>
<field name="doctext">
&lt;p&gt;You are not calling your anonymous subs as methods, thus they don't get any invocant (&lt;c&gt;$self&lt;/c&gt;). You could call them like this:&lt;/p&gt;

&lt;c&gt;
my $method = $a-&gt;answers-&gt;{answers_comments};
$a-&gt;answers-&gt;$method(
   123,
   134,
   145,
   { 
      order =&gt; "desc",
      sort  =&gt; "votes",
   },
);
&lt;/c&gt;

&lt;p&gt;Then they'll have an invocant.&lt;/p&gt;

&lt;p&gt;It would be much saner though to install your methods as genuine methods, not coderefs floating around attached to blessed objects.&lt;/p&gt;

&lt;c&gt;
# in Answers.pm
use Sub::Name 'subname';
*answers_comments = subname(
   "Net::StackExchange::V2::Answer::answers_comments",
   one_param("answers","comments"),
);
&lt;/c&gt;

&lt;p&gt;Now you can call it like a proper method:&lt;/p&gt;
&lt;c&gt;
$a-&gt;answers-&gt;answers_comments(
   123,
   134,
   145,
   { 
      order =&gt; "desc",
      sort  =&gt; "votes",
   },
);
&lt;/c&gt;
&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-757127"&gt;
&lt;small&gt;&lt;small&gt;
&lt;tt&gt;perl -E'sub Monkey::do{say$_,for@_,do{($monkey=&amp;#x5B;caller(0)]-&gt;&amp;#x5B;3])=~s{::}{ }and$monkey}}"Monkey say"-&gt;Monkey::do'
&lt;/tt&gt;&lt;/small&gt;&lt;/small&gt;
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
1014174</field>
<field name="parent_node">
1014174</field>
</data>
</node>
