raku-community-modules / URI

Raku realization of URI — Uniform Resource Identifiers handler
Artistic License 2.0
3 stars 14 forks source link

Problem when used in a module that is subsequently required #30

Closed jonathanstowe closed 8 years ago

jonathanstowe commented 8 years ago

I found this when trying to 'require LWP::Simple' and then use it's methods:

Cannot invoke this object (REPR: Null; VMNull)
  in sub scheme-port at /home/jonathan/.rakudobrew/moar-nom/install/share/perl6/site/sources/07EE6C07F38281215C37955BB3BC16CFA9604F8E (URI::DefaultPort) line 36
  in method default-port at /home/jonathan/.rakudobrew/moar-nom/install/share/perl6/site/sources/E6932313C3FA27F20E3F940809AFC1198E0EC2E5 (URI) line 150
  in method port at /home/jonathan/.rakudobrew/moar-nom/install/share/perl6/site/sources/E6932313C3FA27F20E3F940809AFC1198E0EC2E5 (URI) line 162
  in method parse_url at /home/jonathan/.rakudobrew/moar-nom/install/share/perl6/site/sources/2A99795C71C31D3D9A9D39DCFC0379F0F4CDEDC5 (LWP::Simple) line 365
  in method request_shell at /home/jonathan/.rakudobrew/moar-nom/install/share/perl6/site/sources/2A99795C71C31D3D9A9D39DCFC0379F0F4CDEDC5 (LWP::Simple) line 58
  in method get at /home/jonathan/.rakudobrew/moar-nom/install/share/perl6/site/sources/2A99795C71C31D3D9A9D39DCFC0379F0F4CDEDC5 (LWP::Simple) line 31
  in method getstore at /home/jonathan/.rakudobrew/moar-nom/install/share/perl6/site/sources/2A99795C71C31D3D9A9D39DCFC0379F0F4CDEDC5 (LWP::Simple) line 344
  in block <unit> at tt line 3

where `tt is

try require LWP::Simple;

say ::('LWP::Simple').getstore('http://rabidgravy.com/index.html', 'test');

Though it can be reqplicated with a module:

use URI;

class TestURIRequire {
    method test(Str $uri) {
        my $u = URI.new($uri);
        $u.port;
    }
}

And testing it with

use Test;
plan 2;

require TestURIRequire;

my $port;

lives-ok { $port = ::("TestURIRequire").test('http://example.com'); }, "can use URI in a module that is itself required rather than used";
is $port, 80, "and got the right thing back";

Which is all a bit upsetting.

I am working on a fix at the moment.