Skip to content

Commit 6a0e6d4

Browse files
committed
CURFS and CURI basics
1 parent b6dcaa0 commit 6a0e6d4

File tree

2 files changed

+208
-0
lines changed

2 files changed

+208
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
=begin pod
2+
3+
=TITLE class CompUnit::Repository::FileSystem
4+
5+
=SUBTITLE CompUnit::Repository::FileSystem
6+
7+
class CompUnit::Repository::FileSystem
8+
does CompUnit::Repository::Locally
9+
does CompUnit::Repository
10+
{ }
11+
12+
A L<CompUnit::Repository> implementation backed by the filesystem typically used
13+
in development situations. This is what is used by C<-I .> / C<-I lib> (which are
14+
actually C<-I file#.> and C<-I file#lib>) or C<use lib "."> / C<use lib "lib">.
15+
Unlike L<CompUnit::Repository::Installation>, this represents a single distribution.
16+
17+
=head1 Methods
18+
19+
=head2 method candidates
20+
21+
multi method candidates(Str:D $name, :$auth, :$ver, :$api)
22+
multi method candidates(CompUnit::DependencySpecification $spec)
23+
24+
Return all distributions that contain a module matching the specificed C<$name>, C<auth>,
25+
C<ver>, and C<api>.
26+
27+
# assuming one is cloned into the zef git repository...
28+
my $repo = CompUnit::Repository::FileSystem.new(prefix => $*CWD);
29+
my $dist = $repo.candidates("Zef").head;
30+
say "Zef version: " ~ $dist.meta<version>;
31+
32+
=head2 method files
33+
34+
multi method files(Str:D $name, :$auth, :$ver, :$api)
35+
multi method files(CompUnit::DependencySpecification $spec)
36+
37+
Return all distributions that match the specified C<auth> C<ver> and C<api>, and
38+
contains a non-module file matching the specified C<$name>.
39+
40+
# assuming one is cloned into the zef git repository...
41+
my $repo = CompUnit::Repository::FileSystem.new(prefix => $*CWD);
42+
say $repo.files('bin/zef', :ver<419.0+>).head.<name> // "Nada"; # OUTPUT: «Nada␤»
43+
say $repo.files('resources/config.txt', :ver<419.0+>).head.<name> // "Nada"; # OUTPUT: «Nada␤»
44+
45+
say $repo.files('bin/zef', :ver<0.4.0+>).head.<name>; # OUTPUT: «zef␤»
46+
say $repo.files('resources/config.txt', :ver<0.4.0+>).head.<name>; # OUTPUT: «zef␤»
47+
48+
=head2 method resolve
49+
50+
method resolve(CompUnit::DependencySpecification $spec --> CompUnit:D)
51+
52+
Returns a L<CompUnit> mapped to the highest version distribution matching C<$spec> from
53+
the first repository in the repository chain that contains any version of a distribution
54+
matching C<$spec>.
55+
56+
=head2 method need
57+
58+
method need(
59+
CompUnit::DependencySpecification $spec,
60+
CompUnit::PrecompilationRepository $precomp = self.precomp-repository(),
61+
CompUnit::PrecompilationStore :@precomp-stores = self!precomp-stores(),
62+
--> CompUnit:D)
63+
64+
65+
Loads and returns a L<CompUnit> which is mapped to the highest version distribution
66+
matching C<$spec> from the first repository in the repository chain that contains
67+
any version of a distribution matching C<$spec>.
68+
69+
=head2 method load
70+
71+
method load(IO::Path:D $file --> CompUnit:D)
72+
73+
Load the C<$file> and return a L<CompUnit> object representing it.
74+
75+
=head2 method loaded
76+
77+
method loaded(--> Iterable:D)
78+
79+
Returns all L<CompUnit>s this repository has loaded.
80+
81+
=head2 method short-id
82+
83+
method short-id()
84+
85+
Returns the repo short-id, which for this repository is C<file>.
86+
87+
=end pod
88+
89+
# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
=begin pod
2+
3+
=TITLE class CompUnit::Repository::Installation
4+
5+
=SUBTITLE CompUnit::Repository::Installation
6+
7+
class CompUnit::Repository::Installation
8+
does CompUnit::Repository::Locally
9+
does CompUnit::Repository::Installable
10+
{ }
11+
12+
A L<CompUnit::Repository> implementation backed by the filesystem, but uses an internal
13+
storage format to:
14+
15+
=item Handle case sensitivity issues on filesystems that may conflict as a C<CompUnit::Repository::FileSystem>.
16+
=item Handle allowable filename issues (e.g. unicode) on filesystems that don't support them.
17+
=item Allow multiple distributions, possibly with the same name, to be installed in a single repository.
18+
=item Enable faster module loading.
19+
20+
Because of the internal storage format the usual way to add a distribution is not by copying
21+
files but by calling L<CompUnit::Repository::Installation#method_install>.
22+
23+
=head1 Methods
24+
25+
=head2 method install
26+
27+
method install(Distribution $distribution, Bool :$force)
28+
29+
Copies modules into a special location so that they can be loaded afterwards.
30+
31+
C<:$force> will allow installing over an existing distribution that has the same C<name>,
32+
C<auth>, C<api>, and C<ver>. Otherwise such a situation will result in L<Failure>.
33+
34+
my $inst-repo = CompUnit::RepositoryRegistry.repository-for-name("site");
35+
my $dist = Distribution::Path.new(...);
36+
$inst-repo.install($dist);
37+
38+
=head2 method uninstall
39+
40+
method uninstall(Distribution $distribution)
41+
42+
Removes the C<$distribution> from the repository. C<$distribution> should be obtained from
43+
the repository it is being removed from:
44+
45+
my $inst-repo = CompUnit::RepositoryRegistry.repository-for-name("site");
46+
my $dist = $inst-repo.candidates("Acme::Unused").head;
47+
$inst-repo.uninstall($dist);
48+
49+
=head2 method candidates
50+
51+
multi method candidates(Str:D $name, :$auth, :$ver, :$api)
52+
multi method candidates(CompUnit::DependencySpecification $spec)
53+
54+
Return all distributions that contain a module matching the specificed C<$name>, C<auth>,
55+
C<ver>, and C<api>.
56+
57+
my $inst-repo-path = CompUnit::RepositoryRegistry.repository-for-name("perl").prefix;
58+
my $inst-repo = CompUnit::Repository::Installation.new(prefix => $inst-repo-path);
59+
my $dist = $inst-repo.candidates("Test").head;
60+
say "Test version: " ~ $dist.meta<ver>; # OUTPUT: «6.d␤»
61+
62+
=head2 method files
63+
64+
multi method files(Str:D $name, :$auth, :$ver, :$api)
65+
multi method files(CompUnit::DependencySpecification $spec)
66+
67+
Return all distributions that match the specified C<auth> C<ver> and C<api>, and
68+
contains a non-module file matching the specified C<$name>.
69+
70+
# assuming Zef is installed to the default location...
71+
my $repo = CompUnit::RepositoryRegistry.repository-for-name("site");
72+
73+
say $repo.files('bin/zef', :ver<419.0+>).head.<name> // "Nada"; # OUTPUT: «Nada␤»
74+
say $repo.files('resources/config.txt', :ver<419.0+>).head.<name> // "Nada"; # OUTPUT: «Nada␤»
75+
76+
say $repo.files('bin/zef', :ver<0.4.0+>).head.<name>; # OUTPUT: «zef␤»
77+
say $repo.files('resources/config.txt', :ver<0.4.0+>).head.<name>; # OUTPUT: «zef␤»
78+
79+
=head2 method resolve
80+
81+
method resolve(CompUnit::DependencySpecification $spec --> CompUnit:D)
82+
83+
Returns a L<CompUnit> mapped to the highest version distribution matching C<$spec> from
84+
the first repository in the repository chain that contains any version of a distribution
85+
matching C<$spec>.
86+
87+
=head2 method need
88+
89+
method need(
90+
CompUnit::DependencySpecification $spec,
91+
CompUnit::PrecompilationRepository $precomp = self.precomp-repository(),
92+
CompUnit::PrecompilationStore :@precomp-stores = self!precomp-stores(),
93+
--> CompUnit:D)
94+
95+
Loads and returns a L<CompUnit> which is mapped to the highest version distribution
96+
matching C<$spec> from the first repository in the repository chain that contains
97+
any version of a distribution matching C<$spec>.
98+
99+
=head2 method load
100+
101+
method load(IO::Path:D $file --> CompUnit:D)
102+
103+
Load the C<$file> and return a L<CompUnit> object representing it.
104+
105+
=head2 method loaded
106+
107+
method loaded(--> Iterable:D)
108+
109+
Returns all L<CompUnit>s this repository has loaded.
110+
111+
=head2 method short-id
112+
113+
method short-id()
114+
115+
Returns the repo short-id, which for this repository is C<inst>.
116+
117+
=end pod
118+
119+
# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6

0 commit comments

Comments
 (0)