Hey,<br><br>Seems to be working for me:<br><br>-- TestFh.pm --<br><br>  package TestFh;<br><br>  use strict;<br>  use warnings;<br><br>  use IO::File;<br><br>  sub test_fh {<br>      my ( $fh ) = @_;<br>      printf &quot;fileno: %d\n&quot;, $fh-&gt;fileno();<br>
  }<br><br>  1;<br><br>-- <a href="http://test.pl">test.pl</a> --<br><br>  #!/usr/bin/perl<br><br>  use strict;<br>  use warnings;<br><br>  use TestFh;<br><br>  open my $fh, &quot;&gt;test.txt&quot;<br>      or die $!;<br>
<br>  TestFh::test_fh($fh);<br><br>-- Output --<br><br>  $ perl <a href="http://test.pl">test.pl</a><br>  fileno: 3<br><br>So, unless I&#39;m not understanding the problem, maybe Moose is getting in the way? Try writing a small test script to get what you want and then see if IO::Handle magic kicks in. Otherwise, i&#39;m out of ideas :(<br>
<br>Alfie<br><br><div class="gmail_quote">On Tue, Jan 12, 2010 at 6:09 PM, Toby Corkindale <span dir="ltr">&lt;<a href="mailto:toby.corkindale@strategicdata.com.au">toby.corkindale@strategicdata.com.au</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">Alfie John wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hey Toby,<br>
<br>
When you use IO::Handle etc, all regular handles are automagically blessed into IO::Handle objects:<br>
<br>
-- 8&lt; --<br>
<br>
  $ perl -we &#39;use IO::File; open my $fh, &quot;&gt;test.txt&quot;; $fh-&gt;print( &quot;hello world&quot; )&#39;<br>
  $ cat test.txt<br>
  Hello world<br>
<br>
-- &gt;8 --<br>
<br>
Pretty elegant huh :)<br>
</blockquote>
<br></div>
I had seen someone else mention that, but when I tried it, it failed - I think because you need to &quot;use IO::File&quot; in the calling class before opening the file -- and I don&#39;t have control over the calling code.<div class="im">
<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
As for FileHandle, haven&#39;t used it. Would subclassing FileHandle do what you want? All that Moose stuff looks a bit ugly.<br>
</blockquote>
<br></div>
Hmm, same problem as above -- how to deal with not having control over the point where it&#39;s opened, just receiving the parameter into your code.<br>
<br>
thanks!<br>
Toby<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div></div><div class="h5">
On Tue, Jan 12, 2010 at 5:29 PM, Toby Corkindale &lt;<a href="mailto:toby.corkindale@strategicdata.com.au" target="_blank">toby.corkindale@strategicdata.com.au</a> &lt;mailto:<a href="mailto:toby.corkindale@strategicdata.com.au" target="_blank">toby.corkindale@strategicdata.com.au</a>&gt;&gt; wrote:<br>

<br>
    Old-school Perl file handles looked like this:<br>
<br>
     open(INPUT, &quot;&lt;$filename&quot;);<br>
<br>
    Then later they could be:<br>
<br>
     open(my $input, &quot;&lt;$filename&quot;);<br>
<br>
    New-school filehandles are:<br>
<br>
     my $input = IO::File-&gt;new($filename, &#39;r&#39;);<br>
<br>
    And interregnum filehandles were:<br>
<br>
     my $fh = FileHandle-&gt;new($filename, &#39;r&#39;);<br>
<br>
    I want to have a method which accepts all, but operates upon them<br>
    using new-school object methods, ie. $file-&gt;autoflush(1) or<br>
    $file-&gt;input_line_number;<br>
<br>
<br>
    Currently I&#39;m doing it via the following simplified code example,<br>
    but I wondered if there was a more elegant solution?<br>
<br>
<br>
    package Thingy;<br>
    use Moose;<br>
    use IO::Handle;<br>
<br>
    has &#39;input&#39; =&gt; (<br>
     is =&gt; &#39;rw&#39;,<br>
     isa =&gt; &#39;FileHandle&#39;, # Native Moose type, not same as FileHandle<br>
    );<br>
<br>
    around &#39;BUILDARGS&#39; =&gt; sub {<br>
     my ($orig, $class, $args) = @_;<br>
     unless (blessed $args{input} and $args{input}-&gt;isa(&#39;IO::Handle&#39;)) {<br>
       $args-&gt;{input} = IO::Handle-&gt;new-&gt;fdopen(fileno($args-&gt;{input}));<br>
     }<br>
     return $args;<br>
    };<br>
    _______________________________________________<br>
    Melbourne-pm mailing list<br></div></div>
    <a href="mailto:Melbourne-pm@pm.org" target="_blank">Melbourne-pm@pm.org</a> &lt;mailto:<a href="mailto:Melbourne-pm@pm.org" target="_blank">Melbourne-pm@pm.org</a>&gt;<div class="im"><br>
    <a href="http://mail.pm.org/mailman/listinfo/melbourne-pm" target="_blank">http://mail.pm.org/mailman/listinfo/melbourne-pm</a><br>
<br>
<br>
</div></blockquote><font color="#888888">
<br>
<br>
-- <br>
Strategic Data Pty Ltd<br>
Ph: 03 9340 9000<br>
</font></blockquote></div><br>