Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about Readonly::XS.pm..$MAGIC_COOKIE 1

Status
Not open for further replies.

whn

Programmer
Oct 14, 2007
265
US
Hi, Experts,

I have been using Readonly.pm for quite some time on various platforms, such Solaris, AIX, Redhat, SUSE 9 & 10 with perl 5.8.8 or lower and never had any problems until I started running my codes (CLI) on SUSE 11 with perl 5.10.0.

The error I got:

String found where operator expected at XS.pm line 36, near "Carp::croak "Readonly::XS is not a standalone module. You should not use it directly.""
(Do you need to predeclare Carp::croak?)


For your convenience, below is the part of XS.pm:
Code:
package Readonly::XS;

use strict;
use warnings;
use vars qw($VERSION $MAGIC_COOKIE %PL_COMPAT);

$VERSION = '1.04';

require XSLoader;
XSLoader::load('Readonly::XS', $VERSION);

# It is an error to use this from any module but Readonly.
# But sooner or later, someone will.
BEGIN
{
    no warnings 'uninitialized';
    if ($MAGIC_COOKIE ne "Do NOT use or require Readonly::XS unless you're me.")
    {
        require Carp;
        Carp::croak "Readonly::XS is not a standalone module. You should not use it directly."; [b]# Line 36!![/b]
    }
}

BTW, I got this error only on SUSE 11 (perl 5.10.0). Could someone kindly explain to me how the variable $MAGIC_COOKIE is set and why this error is only seen on SUSE 11? How to fix this problem?

Many thanks.
 
MAGIC_COOKIE is set early in Readonly.pm, which calls Readonly::XS if it is available on your system.

I think you need to update Readonly::XS, sounds like this bug describes your problem.

I can reproduce the problem in Cygwin with perl 5.10, and making the same change fixes it for me too:

Code:
$ perl -e 'if (0) { require Carp; Carp::croak "a test string"; }'
String found where operator expected at -e line 1, near "Carp::croak "a test string""
        (Do you need to predeclare Carp::croak?)
syntax error at -e line 1, near "Carp::croak "a test string""
Execution of -e aborted due to compilation errors.

$ perl -e 'if (0) { require Carp; Carp::croak("a test string"); }'

$

Annihilannic.
 
Thank you, Annihilannic.

That helps a lot!!

A follow-up question: why didn't I have this problem with perl 5.8.8?

Thanks again for your help.
 
5.10.0 is more strict with certain syntaxes than 5.8.8 was.

Kirsle.net | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top