-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from nyarla/kalaclista-context-path
feat(Kalaclista::Context::Path): add new class for filepath context
- Loading branch information
Showing
3 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package Kalaclista::Context::Path; | ||
|
||
use v5.38; | ||
|
||
use Exporter::Lite (); | ||
use Carp qw(croak); | ||
|
||
use Kalaclista::Path; | ||
|
||
our @EXPORT = qw(rootdir); | ||
|
||
sub rootdir { state $root ||= shift; $root } | ||
|
||
sub import { | ||
croak qq|you can't pass to more than 1 arguments| if @_ > 2; | ||
croak qq|missing regexp to detect rootdir; usage: 'use @{[ __PACKAGE__ ]} qr{^lib\$}'| if @_ != 2; | ||
|
||
rootdir( Kalaclista::Path->detect( pop @_ ) ); | ||
|
||
my $exporter = Exporter::Lite->can('import'); | ||
goto $exporter; | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env perl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Test2::V0; | ||
|
||
subtest failed => sub { | ||
my $failure = dies { | ||
eval 'use Kalaclista::Context::Path'; | ||
die $@ if $@; | ||
}; | ||
|
||
like $failure, qr|^missing regexp to detect rootdir; usage: 'use Kalaclista::Context::Path qr\{\^lib\$\}'|; | ||
}; | ||
|
||
subtest ok => sub { | ||
my $success = lives { | ||
eval 'use Kalaclista::Context::Path qr{^t$}'; | ||
die $@ if $@; | ||
}; | ||
|
||
ok $success; | ||
}; | ||
|
||
done_testing; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env perl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Test2::V0; | ||
|
||
use Kalaclista::Path; | ||
use Kalaclista::Context::Path qr{^t$}; | ||
|
||
subtest rootdir => sub { | ||
my $test = rootdir; | ||
my $expected = Kalaclista::Path->detect(qr{^t$}); | ||
|
||
is $test->to_string, $expected->to_string; | ||
}; | ||
|
||
done_testing; |