Tyil
Tyil

Reputation: 1807

Module name matching

I have a list of module names, as Strs, extracted from the META6.json. Specifically, the depends array. This contains the following entries:

"Config::Parser::toml:ver<1.0.1+>",                                   
"Config:api<1>:ver<1.3.5+>",                                      
"Dist::Helper:ver<0.21.0+>",                                      
"Hash::Merge",                                                  
"Terminal::Getpass:ver<0.0.5+>",

How can I best match individual entries? Doing eq string matches isn't specific enough, as Config wouldn't match Config:api<1>:ver<1.3.5+> as a string. Trying to match using .starts-with also wouldn't work correctly, as Config:ver<1.3.5> wouldn't match Config:api<1>:ver<1.3.5>.

Upvotes: 6

Views: 172

Answers (1)

ugexe
ugexe

Reputation: 5726

use Zef::Distribution::DependencySpecification;

my $spec-ver-all     = Zef::Distribution::DependencySpecification.new("Foo::Bar");
my $spec-ver-zero    = Zef::Distribution::DependencySpecification.new("Foo::Bar:ver<0>");
my $spec-ver-one     = Zef::Distribution::DependencySpecification.new("Foo::Bar:ver<1>");
my $spec-ver-oneplus = Zef::Distribution::DependencySpecification.new("Foo::Bar:ver<1+>");
my $spec-ver-two     = Zef::Distribution::DependencySpecification.new("Foo::Bar:ver<2>");
my $spec-ver-three   = Zef::Distribution::DependencySpecification.new("Foo::Bar:ver<3>");

say $spec-ver-one.spec-matcher($spec-ver-all);         # True
say $spec-ver-one.spec-matcher($spec-ver-two);         # False
say $spec-ver-zero.spec-matcher($spec-ver-oneplus);    # False
say $spec-ver-oneplus.spec-matcher($spec-ver-oneplus); # True
say $spec-ver-three.spec-matcher($spec-ver-oneplus);   # True

Upvotes: 8

Related Questions