I have a confession: I can't get a Foo example to work! *embarrassed
blush* To be more truthful, I can't get one working using the data
handle. Here is a working example:
use Inline Foo => <<'EOF';
sub barble (@) { foo-print @_, "\n"; }
EOF
barble ("I am a foo.");
Here is a non-working example:
use Inline Foo;
barble ("I am a foo.");
__DATA__
__Foo__
sub barble { foo-print @_, "\n"; }
When I step through the code with the debugger, I find that it boils
down to this regexp:
@{$DATA{$pkg}} = split /(?m)(__\S+?__\n)/, <Inline::DATA>;
Why? Well... here's a secret I didn't mention: the non-working sample
code actually works, but only some of the time. It works when I use
Unix line endings, "\n", but fails with DOS line endings, "\r\n". :-))
My fix came from the perlport page. It works for Unix & Win32, but not
for Macintosh. :-( We need to look at io disciplines or such to get
this right for the general case. I don't even have a clue with VMS
does.
First, at the top of Inline.pm:
use Socket qw(:crlf);
Then in read_DATA, replace:
@{$DATA{$pkg}} = split /(?m)(__\S+?__\n)/, <Inline::DATA>;
with:
my $l = <Inline::DATA>;
$l =~ s/$CR?$LF/\n/g;
@{$DATA{$pkg}} = split /(?m)(__\S+?__\n)/, $l; #<Inline::DATA>;
as recommended by perlport.
Cheers,
--binkley