On Tue, Apr 29, 2014 at 12:56 PM, Normand <norm...@linux.vnet.ibm.com> wrote:
> Hi there,
> I have an error as detailed in the attached tst1.t perl script where the
> "use Readonly::XS;" line is failing.I tried to use perl -d debug mode but
> not working as use line is part of the compile section.
> I do not know how to investigate such a problem, so I would appreciate any
> suggestion.

Normand,

One trick you can use here is to eval the "use Readonly; use
Readonly::XS" so that it happens at runtime rather than compile time.
Alternatively, you can use "require", so it now looks like this:

  #!/usr/bin/perl

  use strict;
  use warnings;

  require Readonly;
  require Readonly::XS;

And if we run it with Devel::Trace, we now get some useful output
which pinpoints the real error:

  $ perl -d:Trace tst1.txt
  [ LOTS OF OUTPUT ]
  ...
  >> /usr/local/lib/perl/5.14.2/Readonly/XS.pm:29:     if
($MAGIC_COOKIE ne "Do NOT use or require Readonly::XS unless you're
me.")
  >> /usr/local/lib/perl/5.14.2/Readonly/XS.pm:31:         require Carp;
  >> /usr/local/lib/perl/5.14.2/Readonly/XS.pm:32:
Carp::croak("Readonly::XS is not a standalone module. You should not
use it directly.");
  ---
  [ LOTS MORE OUTPUT ]

So Readonly.pm is doing "eval 'use Readonly::XS';", which croaks, and
leaves things in a weird state so when tst1.txt comes along and says
"use Readonly::XS", you get the unhelpful error message. (Perhaps a
bug in Perl, I think I'll bring this up with Perl5 Porters).

Hope that helps.

-- Matthew Horsfall (alh)

Reply via email to