This is perl, v5.8.8 built for cygwin-thread-multi-64int

Please forgive the size of the test example that is included. It is as small as I could make it and still demonstrate the apparent bug.

When working with __DATA__ in conjunction with sockets, the first read of the filehandle breaks. If I tell() the filehandle the tell resolves to the wrong location in the file (EXAMPLE 1), if I don't tell(), the filehandle reads twice. Any subsequent call to the filehandle works properly. (EXAMPLE 2)

###### EXAMPLE 1 $ telnet localhost 7171 Trying 127.0.0.1... ) ; our $T ; use strict ; 1; __DATA__ SELECT * FROM blart ; _______________________ ) ; our $T ; use strict ; 1; __DATA__ SELECT * FROM blookie ; Connection closed by foreign host. ######## EXAMPLE 2 $ telnet localhost 7171 Trying 127.0.0.1... SELECT * FROM blart ; _______________________ SELECT * FROM blookie ;
TEST CODE FOLLOWS:

#! /usr/bin/perl -w use Test::Server ; my $S = Test::Server->new( max_servers => 4, max_requests => 100, reverse_lookups => 'off', background => 1, host => '127.0.0.1', proto => 'TCP', port => 7171 ) ; $S->run(); package Test::Server; use Test::Bar ; use Net::Server::PreForkSimple; @ISA = qw(Net::Server::PreForkSimple); use strict ; sub process_request { my $A = Test::Bar->new(table => "blart") ; my $B = Test::Bar->new(table => "blookie") ; print $A->output() ; print "_______________________\n\n" ; print $B->output() ; } 1 ; package Test::Bar ; use Exporter ; our @ISA = qw(Exporter) ; use Test +::Foo ; push @ISA, qw(Test::Foo) ; our @EXPORT = qw($T) ; our $T ; use strict +; 1; __DATA__ SELECT * FROM <TMPL_VAR NAME=table> ; package Test::Foo ; use Exporter ; use HTML::Template ; our @ISA = qw(Exporter) ; sub new { my $class = shift ; my %foo = @_ ; my $Tref ; # reference to a scalar containing a Template my $useblock = 'use ' . $class . ' qw($T);' ; eval $useblock ; my $refblock = '$Tref = \$' . $class . '::T;' ; eval $refblock ; my $self = \%foo ; bless($self,$class) ; $self->{'__TEMPLATE__'} = $Tref ; my $preload = $self->loadfh() ; return $self ; } sub loadfh { my $self = shift ; my $Tref = $self->{'__TEMPLATE__'} ; return 1 if ($$Tref =~ /\w+/) ; my $class = ref($self) ; my $fh ; my $localDATA = $class . '::DATA'; my $fhblock = '$fh = ' . '*' . $localDATA . ';' ; eval($fhblock); tell($fh) ; while(<$fh>) { $$Tref .= $_ ; } return 0 ; } sub output { my $self = shift ; my $Tref = delete $self->{'__TEMPLATE__'} ; my $t = HTML::Template->new_scalar_ref($Tref, die_on_bad_params => + 0); $t->clear_params() ; $t->param(%$self) ; $self->{'__TEMPLATE__'} = $Tref; return $t->output(); } sub fields { my $self = shift ; my $Tref = delete $self->{'__TEMPLATE__'} ; my $t = HTML::Template->new_scalar_ref($Tref, die_on_bad_params => + 0); $t->clear_params() ; my @f = $t->param() ; $self->{'__TEMPLATE__'} = $Tref; return @f ; } 1 ;

In reply to Bug in __DATA__ filehandle by prefectuous

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.