Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Error with CPAN module XML-BMEcat

by derion (Sexton)
on Aug 10, 2017 at 09:02 UTC ( [id://1197137]=perlquestion: print w/replies, xml ) Need Help??

derion has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I am trying to use the XML-BMEcat Module and I presume that there is a problem with something outdated but I am absolutely stuck. There are some subroutines with similar problems, e.g.:

sub creatCatalogGroup { my ($self, $key) = @_; # pls.don't forget this problem (exists $self->{$key}) ? return $self->{$key} : return Push2PsH($self, $key, CatalogGroup->new()); }

Calling it with:

my $CatalogGroup = $GroupSystem->creatCatalogGroup('02');

Throws an error and the script stops:

Not a HASH reference at /cpan/XML/BMEcat.pm line 637.

which is (exists $self->{$key}) ? return $self->{$key} :

Data::Dumper gives me
$VAR1 = bless( 
{}
, 'GroupSystem' );
$VAR2 = '02';
for @_

Now I cannot stop thinking that it must be about exists defined but that seems not logical to me. I tried it on perl 5.10.1 and 5.20.2 which are the versions I have available on webservers.

As far as I read everywhere exists is not deprecated but defined is that makes me think I am on the wrong track thinking about this part of the subroutine.

I would appreciate any hint into the right direction.

Cheers Niko

Replies are listed 'Best First'.
Re: Error with CPAN module XML-BMEcat
by syphilis (Archbishop) on Aug 10, 2017 at 12:24 UTC
    I would appreciate any hint into the right direction

    I can reproduce the error with:
    use warnings; use strict; my @k = (1,2,3); my $self = \@k; # an ARRAY reference my $ret = foo($self, 'key'); print "$ret\n"; sub foo { my ($self, $key) = @_; (exists $self->{$key}) ? return $self->{$key} : return 0; }
    Update: But if I set $self to a string (instead of a reference to the array) && I turn off strictures, then the program runs to completion and foo() returns 0.

    Cheers,
    Rob
      Thank you very much for your feedback Rob. As many other starting to post here I do not feel very experienced and questioning modules listed at CPAN feels wrong but it looks to me that the code should be more like:
      sub creatCatalogGroup { my ($self, $key) = @_; # pls.don't forget this problem (exists @{$self}[0]->{$key}) ? return @{$self}[0]->{$key} : return Push2PsH($self, $key, CatalogGroup->new()); }

      I am not yet sure if it does the right thing, but at least it does not throw an error.

      Cheers

      Niko

        Hi

        Oh wow, thats the authors comment,

        I see the test file is named "Test.pl" most of the cpan-testers didn't run the test file

        I've made fixes, but I've not examined the xml file to check if it makes sense, but the test.pl now runs without problems

        Here is a new version of that distribution, use patch to create it, use patch -p0 -i XML-BMEcat-0.56.patch and get

        patching file XML-BMEcat-0.56/Changes
        patching file XML-BMEcat-0.56/lib/XML/BMEcat.pm
        patching file XML-BMEcat-0.56/Makefile.PL
        patching file XML-BMEcat-0.56/MANIFEST
        patching file XML-BMEcat-0.56/META.json
        patching file XML-BMEcat-0.56/META.yml
        patching file XML-BMEcat-0.56/test.pl
Re: Error with CPAN module XML-BMEcat
by runrig (Abbot) on Aug 10, 2017 at 15:51 UTC
    This is an old library, and it is using pseudo hashes, which are no longer supported. This code needs to be updated (or you need to use an old version of Perl).
Re: Error with CPAN module XML-BMEcat ( Not a HASH reference , Class::PseudoHash )
by Anonymous Monk on Aug 11, 2017 at 01:43 UTC

    Hi,

    Problem is this code

    package GroupSystem; sub new { my $class = shift; my $self = [{}];

    That uses a experimental feature called "pseudo hash" that was deprecated in Perl 5.8.0 (2002-Jul-18) removed in Perl 5.10.0 (2007-Dec-18)

    Therefore, the fix is much simpler than presented in Re^3: Error with CPAN module XML-BMEcat,

    the fix is to inherit from Class::PseudoHash

    package GroupSystem; use Class::PseudoHash; @GroupSystem::ISA = 'Class::PseudoHash';
      Works like a charm, thank you very much!
Re: Error with CPAN module XML-BMEcat
by Anonymous Monk on Aug 10, 2017 at 11:30 UTC
    Hi. First step of debugging is your 20 line program to show the bug. Maybe bug report ends with snippets of modules and dumper output, but you start at the beginning.

      Thank you for your hint, I felt pretty safe that there is no need to check / debug that code for I just used the example code from the CPAN website:

      use XML::BMEcat; use File::Basename; my $BMEcat = XML::BMEcat->new(); $BMEcat->setOutfile("catalog.xml"); my $GroupSystem = $BMEcat->creatGroupSystem(); my $CatalogGroup = $GroupSystem->creatCatalogGroup("04");
      But using perl -d gave some more input:
      GroupSystem::creatCatalogGroup('GroupSystem=ARRAY(0xb3bf70)', 04) called at ./bme_export.pl line 11

      Still I am desperated and lost but something new to investigate, thanks again.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1197137]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2024-04-19 12:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found