Can I forward to declare a Perl 6 class, which I will define later?

Is it possible to forward the declaration of the class that I want to load and use later, without interpolating its name? I am trying something like this:

my class Digest::MD5 {};
require ::('Digest::MD5');
put Digest::MD.new.md5_hex("My awesome data to hash");

I know I can do this with interpolation, but I was hoping to skip this step:

require ::('Digest::MD5');
put ::('Digest::MD5').new.md5_hex("My awesome data to hash");

It seemed to me that I saw something similar in some basic classes, but perhaps they had additional material.

+6
source share
1 answer

Divide the question:

  • Can I forward a class declaration?

    , .
    ( Rakudo )
    , , .

    class Foo {...}
    class Foo {
    }
    
  • ::('Digest::MD5') ?

    require -

    put (require Digest::MD5).new.md5_hex("My awesome data to hash");
    

    :

    sub term:<Digest::MD5> () { once require Digest::MD5 }
    
    put Digest::MD5.new.md5_hex("My awesome data to hash");
    
+8

All Articles