<?xml version="1.0" encoding="windows-1252"?>
<node id="652383" title="Bug or inconsitency? FQN of Package and sub name identical" created="2007-11-22 10:12:39" updated="2007-11-22 05:12:39">
<type id="115">
perlquestion</type>
<author id="123953">
strat</author>
<data>
<field name="doctext">
&lt;p&gt;Good morning,&lt;/p&gt;
&lt;p&gt;I found a strange behaviour of perl when a function has the same fully qualified name as a package name. Here a shortened example:&lt;/p&gt;

&lt;p&gt;Code 1: fails&lt;/p&gt;
&lt;code&gt;
#! /usr/bin/perl
use warnings;
use strict;

package ABCconf;

sub Query {
    my( $package ) = caller;
    print "Query called from $package\n";
    my $x = ABCconf::Query-&gt;new();
}

sub Insert {
    print "Insert called\n";
    my $x = ABCconf::Query-&gt;new(); # &lt;= problem: calls ABCconf::Query and then on its output -&gt;new
} # Insert

package ABCconf::Query;

sub new {
    my $class = shift;
    print "New called: $class\n";
    return bless {}, $class;
} # new

package main;

ABCconf::Query();
print "-" x 60, "\n";
ABCconf::Insert();
&lt;/code&gt;
&lt;p&gt;Output:&lt;/p&gt;
&lt;code&gt;
D:\&gt;perl testBug.pl
Query called from main
New called: ABCconf::Query
------------------------------------------------------------
Insert called
Query called from ABCconf
New called: ABCconf::Query
New called: ABCconf::Query=HASH(0x226290)
Attempt to bless into a reference at testBug.pl line 24.
&lt;/code&gt;

&lt;p&gt;If I put the sub Insert before sub Query, everything works as expected.&lt;/p&gt;
&lt;p&gt;Code 2: works&lt;/p&gt;
&lt;code&gt;
#! /usr/bin/perl
use warnings;
use strict;

package ABCconf;

sub Insert {
    print "Insert called\n";
    my $x = ABCconf::Query-&gt;new();
} # Insert

sub Query {
    my( $package ) = caller;
    print "Query called from $package\n";
    my $x = ABCconf::Query-&gt;new();
}

package ABCconf::Query;

sub new {
    my $class = shift;
    print "New called: $class\n";
    return bless {}, $class;
} # new

package main;

ABCconf::Query();
print "-" x 60, "\n";
ABCconf::Insert();
&lt;/code&gt;
&lt;p&gt;Output:&lt;/p&gt;
&lt;code&gt;
D:\&gt;perl testBug.pl
Query called from main
New called: ABCconf::Query
------------------------------------------------------------
Insert called
New called: ABCconf::Query
&lt;/code&gt;
&lt;p&gt;I know it isn't a good idea to use the same fully qualified name for a package or a sub, but I can't change it. Is this a bug, an inconsistency or a feature?&lt;/p&gt;

&lt;p&gt;Testet with&lt;/p&gt;
&lt;code&gt;
D:\&gt;perl -v
This is perl, v5.8.8 built for MSWin32-x86-multi-thread
(with 18 registered patches, see perl -V for more detail)

Copyright 1987-2007, Larry Wall

Binary build 822 [280952] provided by ActiveState http://www.ActiveState.com
Built Jul 31 2007 19:34:48
...
&lt;/code&gt;

&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-123953"&gt;
&lt;P&gt;
Best regards,&lt;BR&gt;
perl -e "s&gt;&gt;*F&gt;e=&gt;y)\*martinF)stronat)=&gt;print,print v8.8.8.32.11.32"
&lt;/div&gt;&lt;/div&gt;</field>
</data>
</node>
