Skip Menu |

This queue is for tickets about the Module-Metadata CPAN distribution.

Maintainer(s)' notes

Attention bug reporters: issues MUST include the version of Module::Metadata that you are running that exhibit the stated symptoms. thank you!

Report information
The Basics
Id: 74741
Status: open
Priority: 0/
Queue: Module-Metadata

People
Owner: ether [...] cpan.org
Requestors: KENTNL [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.000007
Fixed in: (no value)



Subject: sub main incorrectly triggers the package reporting an invalid namespace
I should probably get a small award for bumping into the most obscure bugs.

If a package has in it: 

    sub main {     }

 

Module::Metadata reports that the same as if somebody had declared

 

    package main; 

Sure, hopefully nobody in the real world does this, 
and I just so happened to be unfortunate enough to have used that in one of my test cases1, and only hit it due to moving the code 
to use Module::Metadata instead of Module::Extract::Namespaces. ( )

But all the same, that's a suspiciously weird and unique bug that slightly worries me.

 

1.https://metacpan.org/source/KENTNL/Dist-Zilla-Plugin-MetaProvides-Package-1.12060502/corpus/dist/DZ2/lib/DZ2.pm


Full test code and sample output

https://gist.github.com/1758943

Subject: sub_main_is_not_package.t
#!/usr/bin/env perl use strict; use warnings; # FILENAME: sub_main_is_not_package.t # CREATED: 02/07/12 23:07:28 by Kent Fredric (kentnl) <kentfredric@gmail.com> # ABSTRACT: A weird bug with module::metadata use Test::More; use Module::Metadata; my $data = <<'__EOD__'; use strict; use warnings; package Example; sub main { return 1; } sub other { return 1; } 1; __EOD__ use IO::String; my $fh = IO::String->new( $data ); my $mm = Module::Metadata->new_from_handle( $fh , 'lib/Example.pm', collect_pod => 0 ); is_deeply( [ sort $mm->packages_inside() ], [ 'Example' ] , 'Should only return \'Example\'') or note explain $mm; done_testing;
Subject: incorrect package including "main" namespace

Urh. I seem to have missunderstood the problem. Having removed sub main { } from the code, it still occurs.

 

Assumptions will get you every time -_-.

 

Still, I don't believe it should be reporting "main" is visible as a "provided" package.

Thanks for your report. The 'main' package is reported because you actually have code in the 'main' package : the 'use strict' and 'use warnings' statements. Moving them past the package declaration removes 'main' from the list of reported packages. So in that regard I think Module::Metadata is correct here. Let me know if you're not convinced. :) Vincent
Looking at it plainly i think it is wrong to claim that a module provides main, since main already exists.
Consider the case where two different files run code or declare symbols in the same package. Which of those files will then 'provides' this package ? I believe the sanest answer is "both of them", and I don't think that 'main' should be treated differently.
Subject: Re: [rt.cpan.org #74741] incorrect package including "main" namespace
Date: Mon, 30 Jul 2012 02:01:56 +0200
To: bug-Module-Metadata [...] rt.cpan.org
From: "Christian Walde" <walde.christian [...] googlemail.com>
As for the case where two modules declare the same package: Sure, programmatically both provide a package. However that is entirely by choice. It happens because someone consciously typed out the appropiate code for that. And more importantly, if they hadn't typed it, the namespace would not exist. In the case of main however the situation is not the same. Nobody made a conscious decision to create the namespace. It exists by default. More importantly though: Code before any declared package is not actually main. It will be declared in whatever namespace the use was called in, as this gist demonstrates: https://gist.github.com/3202670
RT-Send-CC: walde.christian [...] googlemail.com
On 2012-07-29 17:02:21, walde.christian@googlemail.com wrote: Show quoted text
> More importantly though: Code before any declared package is not > actually main. It will be declared in whatever namespace the use was > called in, as this gist demonstrates: > > https://gist.github.com/3202670
I've just created some TODO tests (to be part of 1.000029) for these cases - where there is a $VERSION declaration but no package statement preceding it. (In the test I chose "____caller" to as the unknown namespace the $VERSION assignment will be evaluated in.)