Unblessed Hashref错误

时间:2016-10-24 02:44:32

标签: perl moose hashref

我一直在学习Moose并且正在努力学习我的测试,我不断收到错误信息

Type of argument to keys on reference must be unblessed hashref or arrayref at ./GO2.t line 40, <DATA> chunk 1.

我已经包含了我的.t脚本,我不确定如何修复此错误,并且找不到任何确切的未完成的hashref的答案。我没有包含DATA中的所有内容,只需几次迭代。 我以为我错误地调用了哈希

#!/usr/bin/perl
use warnings;
use strict;
use GO2;
use MooseX::FollowPBP;

use Test::More tests => 44;

#Initialize $_ to prevent warnings in redefinition of $/ as RegEx
$_ = '';
local $/ = /\[Term\]|\[Typedef\]/;

while (<DATA>) {

    # Remove end-of-line characters
    chomp;

    # parse the record using a regular expression
    my $longGoDesc = $_;

    #Create a new GO object
    my $go = GO2->new( 'longGoDesc' => $longGoDesc);

    # ok is a test function that prints ok if the test is true, and
    ok( defined $go->get_id() );
    ok( defined $go->get_def() );
    ok( defined $go->get_name() );
    ok( defined $go->get_namespace() );

    # Initialize is_a counter
    my $isaCount = 0;

    #Loop through the is_a array reference
    foreach my $isaRef ( keys $go->{is_as} ) {
 #Make sure the is_a is defined
            ok( $go->get_is_as()->[$isaRef] );

            #Increment is_a counter
            $isaCount++;
    }

    #Make sure at least one is_a
    ok( $isaCount > 0 );

    # Initialize alt_id counter
    my $altIdCount = 0;

    # Check for alt_id
#       if ( defined $go->{alt_ids} ) {

            #Loop through is_a
            foreach my $altIdRef ( keys $go->{alt_ids} ) {
                    ok( $go->get_alt_ids()->[$altIdRef] );

                    # Increment alt_id counter
                    $altIdCount++;


    }

    #Make sure at least one alt_id
    ok( $altIdCount > 0 );
}

# Indicate that tests are done
done_testing();

# Everything below __END__ is treated as input for the DATA filehandle.
 __END__
[Term]
id: GO:2001315
name: UDP-4-deoxy-4-formamido-beta-L-arabinopyranose biosynthetic process
namespace: biological_process
alt_id: GO:0019901
def: "The chemical reactions and pathways resulting in the formation of a UDP-4-deoxy-4-formamido-beta-L-arabinopyranose." [CHEBI:47027, GOC:yaf, UniPathway:UPA00032]
synonym: "UDP-4-deoxy-4-formamido-beta-L-arabinopyranose anabolism" EXACT [GOC:obol]
synonym: "UDP-4-deoxy-4-formamido-beta-L-arabinopyranose biosynthesis" EXACT [GOC:obol]
synonym: "UDP-4-deoxy-4-formamido-beta-L-arabinopyranose formation" EXACT [GOC:obol]
synonym: "UDP-4-deoxy-4-formamido-beta-L-arabinopyranose synthesis" EXACT [GOC:obol]
is_a: GO:0009226 ! nucleotide-sugar biosynthetic process
is_a: GO:0046349 ! amino sugar biosynthetic process
is_a: GO:2001313 ! UDP-4-deoxy-4-formamido-beta-L-arabinopyranose metabolic process

[Term]
id: GO:2001316
name: kojic acid metabolic process
namespace: biological_process
alt_id: GO:0019902
def: "The chemical reactions and pathways involving kojic acid." [CHEBI:43572, GOC:di]
synonym: "5-hydroxy-2-(hydroxymethyl)-4H-pyran-4-one metabolic process" EXACT [CHEBI:43572, GOC:obol]
synonym: "5-hydroxy-2-(hydroxymethyl)-4H-pyran-4-one metabolism" EXACT [CHEBI:43572, GOC:obol]
synonym: "C6H6O4 metabolic process" RELATED [CHEBI:43572, GOC:obol]
synonym: "C6H6O4 metabolism" RELATED [CHEBI:43572, GOC:obol]
synonym: "kojic acid metabolism" EXACT [GOC:obol]
is_a: GO:0034308 ! primary alcohol metabolic process
is_a: GO:0042180 ! cellular ketone metabolic process
is_a: GO:0046483 ! heterocycle metabolic process
is_a: GO:1901360 ! organic cyclic compound metabolic process

[Term]
id: GO:2001317
name: kojic acid biosynthetic process
namespace: biological_process
alt_id: GO:0019903
def: "The chemical reactions and pathways resulting in the formation of kojic acid." [CHEBI:43572, GOC:di]
synonym: "5-hydroxy-2-(hydroxymethyl)-4H-pyran-4-one anabolism" EXACT [CHEBI:43572, GOC:obol]
synonym: "5-hydroxy-2-(hydroxymethyl)-4H-pyran-4-one biosynthesis" EXACT [CHEBI:43572, GOC:obol]
synonym: "5-hydroxy-2-(hydroxymethyl)-4H-pyran-4-one biosynthetic process" EXACT [CHEBI:43572, GOC:obol]
synonym: "5-hydroxy-2-(hydroxymethyl)-4H-pyran-4-one formation" EXACT [CHEBI:43572, GOC:obol]
synonym: "5-hydroxy-2-(hydroxymethyl)-4H-pyran-4-one synthesis" EXACT [CHEBI:43572, GOC:obol]
synonym: "C6H6O4 anabolism" RELATED [CHEBI:43572, GOC:obol]
synonym: "C6H6O4 biosynthesis" RELATED [CHEBI:43572, GOC:obol]
synonym: "C6H6O4 biosynthetic process" RELATED [CHEBI:43572, GOC:obol]
synonym: "C6H6O4 formation" RELATED [CHEBI:43572, GOC:obol]
synonym: "C6H6O4 synthesis" RELATED [CHEBI:43572, GOC:obol]
synonym: "kojic acid anabolism" EXACT [GOC:obol]
synonym: "kojic acid biosynthesis" EXACT [GOC:obol]
synonym: "kojic acid formation" EXACT [GOC:obol]
synonym: "kojic acid synthesis" EXACT [GOC:obol]
is_a: GO:0018130 ! heterocycle biosynthetic process
is_a: GO:0034309 ! primary alcohol biosynthetic process
is_a: GO:0042181 ! ketone biosynthetic process
is_a: GO:1901362 ! organic cyclic compound biosynthetic process
is_a: GO:2001316 ! kojic acid metabolic process
synonym: "Roundabout signalling pathway involved in muscle cell chemotaxis toward tendon cell" EXACT [GOC:obol]
synonym: "Roundabout signalling pathway involved in muscle cell chemotaxis towards tendon cell" EXACT [GOC:obol]
is_a: GO:0035385 ! Roundabout signaling pathway
relationship: part_of GO:0036061 ! muscle cell chemotaxis toward tendon cell

[Term]
id: GO:2001284
name: regulation of BMP secretion
namespace: biological_process
alt_id: GO:0019904
def: "Any process that modulates the frequency, rate or extent of BMP secretion." [GOC:sart]
synonym: "regulation of BMP protein secretion" EXACT [GOC:obol]
synonym: "regulation of bone morphogenetic protein secretion" EXACT [GOC:obol]
is_a: GO:0010646 ! regulation of cell communication
is_a: GO:0023051 ! regulation of signaling

1 个答案:

答案 0 :(得分:2)

keys($ref)是一项已被放弃的实验性功能。你不应该使用它。您必须将哈希(keys(%...))或数组(keys(@...))传递给keys

获取引用数组的键:

keys(@{ $ref })

或者简单地说:

0 .. $#{ $ref }

当然,存在访问对象内部的问题。你的代码应该是:

my $is_as_s = $go->get_is_as();
my $isaCount = @$is_as_s;

for my $is_as ( @$is_as_s ) {
   ok($is_as);
}