develooper Front page | perl.perl6.users | Postings from March 2021

Re: Find Packages with prefix ...

Thread Previous | Thread Next
Richard Hainsworth
March 7, 2021 12:06
Re: Find Packages with prefix ...
Message ID:
Interesting question.

I would like to know a good way of doing this. But just to refine the 
question, so that we don't discuss which directory modules are in 
(doesn't matter whether its lib/ or bin/), or whether we use classes and 
inheritance, the interesting (for me) question is: how to find other 
packages that have been installed?

Assume that we have three distributions, Parent, Brother, Sister. Parent 
'provides' 'Top.rakumod', while brother and sister provide 
'Top::Son.rakumod' and 'Top::daughter.rakumod', respectively. Brother 
and Sister have a 'depends': 'Top' in their META6.json.

Each distribution is in its own git repo. And each are installed by zef.

Suppose Top is set up as a class with an interface method 'multi method 
on-starting { ... }', which each sub-class has to implement, and which 
when run, provides the caller with information about the sub-class.

So, now we run an instance of Top (as defined in Parent). It needs to 
look for installed modules that match 'Top::*'. The place to start (I 
think) is '$*REPO', which is a linked list of repositories containing 
the modules that are installed. $*REPO also does the 
|CompUnit::Repository| role, which in turn has a 'need' method.

What I don't understand is how to manipulate $*REPO to get a list of all 
the candidate modules that match 'Top::*', along the whole of the linked 

Once I have the list of candidates, I can use '^can' to check it has a 
'on-starting' method, and then call that method.

If someone could provide a bit of boiler plate code, I would really 
appreciate it.


On 07/03/2021 02:36, Paul Procacci wrote:
> Hey Gents,
> I was toying with an idea of writing a program (shocker!) and in the 
> design of said program I wanted to give the ability to other module 
> writers to extend functionality of the base program.
> The main program would live in bin/ as per normal and claim a 
> namespace of its own.  Call it: SuperDuperProgram
> Within this namespace, I would ideally designate 
> SuperDuperProgram::Modules to be the namespace that modules would live 
> under.  These modules would have their own git repos and depend on 
> SuperDuperProgram being installed.
> Given this, I'd like the main program to perform a prefix search of 
> installed modules with that namespace as a prefix, load said modules 
> it finds, perform callbacks that I would designate as being required 
> to successfully load the module, etc.
> I've read various resources which include the zef source code, the 
> raku docs, etc., yet am still unable to wrap my head around this.
> Any pointers in the right direction as welcomed.
> A mock up of what I had in mind:
> ./bin/SuperDuperProgram
> ###############################
> #!/usr/bin/env raku
> my @modules_with_prefix = 
> search_installed_modules_with_prefix('SuperDuperProgram::Modules');
> for @modules_with_prefix {
>   # require module
>   # perform init callbacks - new() for example
>   # whatever else
> }
> -- 
> __________________
> :(){ :|:& };:

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About