代码之家  ›  专栏  ›  技术社区  ›  Rowland Shaw

为什么WebService::Mappoint在调用new()时抱怨“不是哈希引用”?

  •  1
  • Rowland Shaw  · 技术社区  · 16 年前

    我继承了一些对Microsoft的Mappoint wbeservice进行web服务调用的Perl代码,但在最近的一次升级后,它开始失败,出现了一些神秘的问题:

    不是/usr/lib/perl5/site_perl/5.8.0/WebService/Mappoint.pm第35行的哈希引用。

    没有发布模块的完整代码(毕竟, WebService::Mappoint

    package WebService::Mappoint;
    use SOAP::Lite;
    use FileHandle;
    use fields qw(ini_file remote_object CustomerInfoHeader UserInfoHeader);
    use vars qw(%FIELDS);
    use vars qw($VERSION);
    $VERSION=0.30;
    
    # @drawmap_EU might be incomplete. It might also contain values that should not be here. Please let me know if there is something wrong
    my @EU = (qw(
    ad al am at az by ba be bg hr ch cy cz de dk ee es fo fr fi gb ge gi gr hu is ie it lv lt lu mt nl no pl pt ro sk si se tr ua uk yu
    ));
    my %EU;
    my %NA = (us=>1, ca=>1, mx=>1);
    
    use strict;
    
    my $ini_files = {};
    my ( $user, $password );
    
    my $default_ini_path;
    
    BEGIN {
    
       $default_ini_path = $^O =~ m/windows/i ? 'c:\mappoint.ini' : '/etc/mappoint.ini';
    }
    
    ##############################################################################
    sub new {
        my ( $class, $proxy_url, $inifile_path ) = @_;
    
        no strict 'refs';
        my $self = bless [\%{"${class}::FIELDS"}], $class;
    

    虽然我可以通过足够多的Perl进行筛选,但我还是有点困惑,为什么这会导致问题,尽管我认为您只能支持哈希,而这似乎是一个匿名数组?

    1 回复  |  直到 16 年前
        1
  •  3
  •   BenMorel Manish Pradhan    12 年前

    看起来像是在使用 pseudo-hashes . 数组引用存储在 $self ,但它后来用作哈希引用。现在不推荐使用伪哈希。我建议您使用普通散列对模块进行修补。不确定这是否有帮助:

    my $self = bless { %{"${class}::FIELDS"} }, $class;