Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Checking in changes prior to tagging of version 0.01.

Changelog diff is:

diff --git a/Changes b/Changes
new file mode 100644
index 0000000..e7ad385
--- /dev/null
+++ b/Changes
@@ -0,0 +1,4 @@
+Revision history for Perl extension Project::Libs.
+
+0.01  Wed Nov 24 2010
+      - initial release
  • Loading branch information...
commit 2ff143d32cb4ceb5d6648f9cb443209e03913d88 1 parent 5dd6a7b
Kentaro Kuribayashi authored November 24, 2010
6  .gitignore
... ...
@@ -0,0 +1,6 @@
  1
+META.yml
  2
+Makefile
  3
+blib/
  4
+inc/
  5
+pm_to_blib
  6
+covered
3  .shipit
... ...
@@ -0,0 +1,3 @@
  1
+steps = FindVersion, ChangeVersion, CheckChangeLog, DistTest, Commit,  MakeDist, UploadCPAN
  2
+git.tagpattern = v%v
  3
+CheckChangeLog.files = Changes
4  Changes
... ...
@@ -0,0 +1,4 @@
  1
+Revision history for Perl extension Project::Libs.
  2
+
  3
+0.01  Wed Nov 24 2010
  4
+      - initial release
27  MANIFEST
... ...
@@ -0,0 +1,27 @@
  1
+Changes
  2
+inc/Module/Install.pm
  3
+inc/Module/Install/AuthorTests.pm
  4
+inc/Module/Install/Base.pm
  5
+inc/Module/Install/Can.pm
  6
+inc/Module/Install/Fetch.pm
  7
+inc/Module/Install/Include.pm
  8
+inc/Module/Install/Makefile.pm
  9
+inc/Module/Install/Metadata.pm
  10
+inc/Module/Install/ReadmeMarkdownFromPod.pm
  11
+inc/Module/Install/Repository.pm
  12
+inc/Module/Install/Win32.pm
  13
+inc/Module/Install/WriteAll.pm
  14
+inc/Pod/Markdown.pm
  15
+inc/Test/Builder/Module.pm
  16
+inc/Test/More.pm
  17
+lib/Project/Libs.pm
  18
+Makefile.PL
  19
+MANIFEST			This list of files
  20
+META.yml
  21
+README.mkdn
  22
+t/.gitmodules
  23
+t/basic.t
  24
+t/compile.t
  25
+t/extlib/.gitkeeep
  26
+t/find_inc.t
  27
+t/lib/.gitkeeep
24  MANIFEST.SKIP
... ...
@@ -0,0 +1,24 @@
  1
+\bRCS\b
  2
+\bCVS\b
  3
+\.svn/
  4
+\.git/
  5
+^tags$
  6
+^TAGS$
  7
+^MANIFEST\.
  8
+^Makefile$
  9
+~$
  10
+^#
  11
+\.old$
  12
+^blib/
  13
+^pm_to_blib
  14
+^MakeMaker-\d
  15
+\.gz$
  16
+\.cvsignore
  17
+\.gitignore
  18
+^t/9\d_.*\.t
  19
+^t/perlcritic
  20
+^tools/
  21
+^[^/]+\.yaml$
  22
+^[^/]+\.pl$
  23
+^\.shipit$
  24
+^\.PerlySenseProject/
18  Makefile.PL
... ...
@@ -0,0 +1,18 @@
  1
+use inc::Module::Install;
  2
+
  3
+name     'Project-Libs';
  4
+author   'Kentaro Kuribayashi, <kentarok@cpan.org>';
  5
+license  'MIT';
  6
+all_from 'lib/Project/Libs.pm';
  7
+
  8
+requires 'FindBin::libs';
  9
+test_requires 'Test::More' => 0.96;
  10
+
  11
+tests 't/*.t';
  12
+author_tests 'xt';
  13
+
  14
+readme_markdown_from_pod;
  15
+auto_set_repository;
  16
+auto_include_deps;
  17
+
  18
+WriteAll;
93  README.mkdn
Source Rendered
... ...
@@ -0,0 +1,93 @@
  1
+# NAME
  2
+
  3
+Project::Libs - Add module directories of a project into @INC
  4
+automatically
  5
+
  6
+# SYNOPSIS
  7
+
  8
+    # the simplest way
  9
+    use Project::Libs;
  10
+
  11
+    # add more other dirs into @INC
  12
+    use Project::Libs lib_dirs => [qw(extlib vendor)];
  13
+
  14
+    # add more other marks locate on a project root
  15
+    use Project::Libs project_root_files => [qw(README Changes)];
  16
+
  17
+# DESCRIPTION
  18
+
  19
+Project::Libs automatically adds directories that may contain modules
  20
+which a project depends on.
  21
+
  22
+Imagin there's such a project as below: CPAN-standard file arrangement
  23
+and using git as a SCM (`modules' directory contains git submodules
  24
+and that's written in `.gitmodules').
  25
+
  26
+    |_ PROJECT_ROOT
  27
+       |_ .git
  28
+       |_ .gitmodules
  29
+       |_ Makefile.PL
  30
+       |_ lib/
  31
+       |_ t/
  32
+          |_ lib/
  33
+          |_ compile.t
  34
+          |_ basic.t
  35
+       |_ script/
  36
+          |_ server.pl
  37
+          |_ create.pl
  38
+       |_ extlib/
  39
+       |_ modules/
  40
+          |_ Foo
  41
+             |_ lib/
  42
+          |_ Bar
  43
+             |_ lib/
  44
+          |_ ...
  45
+
  46
+You may bother writing such code as below in all the script located in
  47
+t/*, script/*, or other to add module path into @INC.
  48
+
  49
+    use FindBin;
  50
+    use lib "$FindBin::Bin/../lib";
  51
+    use lib glob "$FindBin::Bin/../modules/*/lib";
  52
+
  53
+To `use Project::Libs' helps you doing that.
  54
+
  55
+In this case, after loading this module, the directories below are
  56
+added into @INC:
  57
+
  58
+- * lib
  59
+
  60
+- * extlib
  61
+
  62
+- * t/lib
  63
+
  64
+- * modules/Foo/lib
  65
+
  66
+- * modules/Bar/lib
  67
+
  68
+# AUTHOR
  69
+
  70
+Kentaro Kuribayashi <kentaro@cpan.org>
  71
+
  72
+# COPYRIGHT AND LICENSE (The MIT License)
  73
+
  74
+Copyright (c) Kentaro Kuribayashi <kentaro@cpan.org>
  75
+
  76
+Permission is hereby granted, free of charge, to any person obtaining
  77
+a copy of this software and associated documentation files (the
  78
+"Software"), to deal in the Software without restriction, including
  79
+without limitation the rights to use, copy, modify, merge, publish,
  80
+distribute, sublicense, and/or sell copies of the Software, and to
  81
+permit persons to whom the Software is furnished to do so, subject to
  82
+the following conditions:
  83
+
  84
+The above copyright notice and this permission notice shall be
  85
+included in all copies or substantial portions of the Software.
  86
+
  87
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  88
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  89
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  90
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  91
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  92
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  93
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
71  lib/Module/Libs.pm
... ...
@@ -1,71 +0,0 @@
1  
-package Module::Libs;
2  
-use strict;
3  
-use warnings;
4  
-use Cwd;
5  
-use FindBin;
6  
-use FindBin::libs;
7  
-use UNIVERSAL::require;
8  
-
9  
-our $VERSION = '0.01';
10  
-
11  
-my @PROJECT_ROOT_FILES = qw(
12  
-    .git
13  
-    .gitmodules
14  
-    Makefile.PL
15  
-);
16  
-
17  
-sub import {
18  
-    my ($class, %args) = @_;
19  
-    my $current_dir = getcwd;
20  
-
21  
-    my $lib_dirs           = delete $args{lib_dirs}           || [];
22  
-    my $project_root_files = delete $args{project_root_files} || [];
23  
-
24  
-    push @PROJECT_ROOT_FILES, @$project_root_files;
25  
-    my @inc = find_inc($FindBin::Bin, $lib_dirs, ());
26  
-
27  
-    if (scalar @inc) {
28  
-        my $inc = join ' ', @inc;
29  
-        eval "use lib qw($inc)";
30  
-    }
31  
-
32  
-    chdir $current_dir;
33  
-}
34  
-
35  
-sub find_inc {
36  
-    my ($current_dir, $lib_dirs, @inc) = @_;
37  
-    return @inc if $current_dir eq '/';
38  
-    chdir $current_dir;
39  
-
40  
-    my @found = grep { -e File::Spec->catfile($current_dir, $_)} @$lib_dirs;
41  
-    push @inc, map { File::Spec->catfile($current_dir, $_)} @found;
42  
-
43  
-    my @root_files = grep { -e $_ } @PROJECT_ROOT_FILES;
44  
-    if (!@root_files) {
45  
-        chdir '..';
46  
-        $current_dir = getcwd;
47  
-        return find_inc($current_dir, $lib_dirs, @inc);
48  
-    }
49  
-
50  
-    for my $file (@root_files) {
51  
-        if ($file eq '.gitmodules') {
52  
-            push @inc, find_git_submodules(
53  
-                $current_dir,
54  
-                File::Spec->catfile($current_dir, '.gitmodules'),
55  
-            )
56  
-        }
57  
-    }
58  
-
59  
-    @inc;
60  
-}
61  
-
62  
-sub find_git_submodules {
63  
-    my ($current_dir, $gitsubmodule) = @_;
64  
-    open my $fh, "< $gitsubmodule" or die $!;
65  
-    my $content = do { local $/ = undef; <$fh> };
66  
-    close $fh;
67  
-    my @submodules = ($content =~ /\[submodule "([^"]+)"\]/g);
68  
-    map { File::Spec->catfile($current_dir, "$_/lib") } @submodules;
69  
-}
70  
-
71  
-!!1;
174  lib/Project/Libs.pm
... ...
@@ -0,0 +1,174 @@
  1
+package Project::Libs;
  2
+use 5.008001;
  3
+use strict;
  4
+use warnings;
  5
+use Cwd;
  6
+use FindBin;
  7
+use FindBin::libs;
  8
+
  9
+our $VERSION = '0.01';
  10
+
  11
+my @PROJECT_ROOT_FILES = qw(
  12
+    .git
  13
+    .gitmodules
  14
+    Makefile.PL
  15
+    Build.PL
  16
+);
  17
+
  18
+sub import {
  19
+    my ($class, %args) = @_;
  20
+    my $current_dir = getcwd;
  21
+
  22
+    my $lib_dirs           = delete $args{lib_dirs}           || [];
  23
+    my $project_root_files = delete $args{project_root_files} || [];
  24
+
  25
+    push @PROJECT_ROOT_FILES, @$project_root_files;
  26
+    my @inc = find_inc($FindBin::Bin, $lib_dirs, ());
  27
+
  28
+    if (scalar @inc) {
  29
+        my $inc = join ' ', @inc;
  30
+        eval "use lib qw($inc)";
  31
+    }
  32
+
  33
+    chdir $current_dir;
  34
+}
  35
+
  36
+sub find_inc {
  37
+    my ($current_dir, $lib_dirs, @inc) = @_;
  38
+    return @inc if $current_dir eq '/';
  39
+    chdir $current_dir;
  40
+
  41
+    my @found = grep { -e File::Spec->catfile($current_dir, $_)} @$lib_dirs;
  42
+    push @inc, map { File::Spec->catfile($current_dir, $_)} @found;
  43
+
  44
+    my @root_files = grep { -e $_ } @PROJECT_ROOT_FILES;
  45
+    if (!@root_files) {
  46
+        chdir '..';
  47
+        $current_dir = getcwd;
  48
+        return find_inc($current_dir, $lib_dirs, @inc);
  49
+    }
  50
+
  51
+    for my $file (@root_files) {
  52
+        if ($file eq '.gitmodules') {
  53
+            push @inc, find_git_submodules(
  54
+                $current_dir,
  55
+                File::Spec->catfile($current_dir, '.gitmodules'),
  56
+            )
  57
+        }
  58
+    }
  59
+
  60
+    @inc;
  61
+}
  62
+
  63
+sub find_git_submodules {
  64
+    my ($current_dir, $gitsubmodule) = @_;
  65
+    open my $fh, "< $gitsubmodule" or die $!;
  66
+    my $content = do { local $/ = undef; <$fh> };
  67
+    close $fh;
  68
+    my @submodules = ($content =~ /\[submodule "([^"]+)"\]/g);
  69
+    map { File::Spec->catfile($current_dir, "$_/lib") } @submodules;
  70
+}
  71
+
  72
+!!1;
  73
+
  74
+__END__
  75
+
  76
+=head1 NAME
  77
+
  78
+Project::Libs - Add module directories of a project into @INC
  79
+automatically
  80
+
  81
+=head1 SYNOPSIS
  82
+
  83
+    # the simplest way
  84
+    use Project::Libs;
  85
+
  86
+    # add more other dirs into @INC
  87
+    use Project::Libs lib_dirs => [qw(extlib vendor)];
  88
+
  89
+    # add more other marks locate on a project root
  90
+    use Project::Libs project_root_files => [qw(README Changes)];
  91
+
  92
+=head1 DESCRIPTION
  93
+
  94
+Project::Libs automatically adds directories that may contain modules
  95
+which a project depends on.
  96
+
  97
+Imagin there's such a project as below: CPAN-standard file arrangement
  98
+and using git as a SCM (`modules' directory contains git submodules
  99
+and that's written in `.gitmodules').
  100
+
  101
+    |_ PROJECT_ROOT
  102
+       |_ .git
  103
+       |_ .gitmodules
  104
+       |_ Makefile.PL
  105
+       |_ lib/
  106
+       |_ t/
  107
+          |_ lib/
  108
+          |_ compile.t
  109
+          |_ basic.t
  110
+       |_ script/
  111
+          |_ server.pl
  112
+          |_ create.pl
  113
+       |_ extlib/
  114
+       |_ modules/
  115
+          |_ Foo
  116
+             |_ lib/
  117
+          |_ Bar
  118
+             |_ lib/
  119
+          |_ ...
  120
+
  121
+You may bother writing such code as below in all the script located in
  122
+t/*, script/*, or other to add module path into @INC.
  123
+
  124
+    use FindBin;
  125
+    use lib "$FindBin::Bin/../lib";
  126
+    use lib glob "$FindBin::Bin/../modules/*/lib";
  127
+
  128
+To `use Project::Libs' helps you doing that.
  129
+
  130
+In this case, after loading this module, the directories below are
  131
+added into @INC:
  132
+
  133
+=over 4
  134
+
  135
+=item * lib
  136
+
  137
+=item * extlib
  138
+
  139
+=item * t/lib
  140
+
  141
+=item * modules/Foo/lib
  142
+
  143
+=item * modules/Bar/lib
  144
+
  145
+=back
  146
+
  147
+=head1 AUTHOR
  148
+
  149
+Kentaro Kuribayashi E<lt>kentaro@cpan.orgE<gt>
  150
+
  151
+=head1 COPYRIGHT AND LICENSE (The MIT License)
  152
+
  153
+Copyright (c) Kentaro Kuribayashi E<lt>kentaro@cpan.orgE<gt>
  154
+
  155
+Permission is hereby granted, free of charge, to any person obtaining
  156
+a copy of this software and associated documentation files (the
  157
+"Software"), to deal in the Software without restriction, including
  158
+without limitation the rights to use, copy, modify, merge, publish,
  159
+distribute, sublicense, and/or sell copies of the Software, and to
  160
+permit persons to whom the Software is furnished to do so, subject to
  161
+the following conditions:
  162
+
  163
+The above copyright notice and this permission notice shall be
  164
+included in all copies or substantial portions of the Software.
  165
+
  166
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  167
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  168
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  169
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  170
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  171
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  172
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  173
+
  174
+=cut
2  t/basic.t
@@ -7,7 +7,7 @@ use Cwd;
7 7
 my $current_dir;
8 8
 BEGIN { $current_dir = getcwd }
9 9
 
10  
-use Module::Libs lib_dirs => [qw(extlib)];
  10
+use Project::Libs lib_dirs => [qw(extlib)];
11 11
 
12 12
 subtest 'find_inc' => sub {
13 13
     for my $path (map {
2  t/compile.t
@@ -2,6 +2,6 @@ use strict;
2 2
 use warnings;
3 3
 use Test::More;
4 4
 
5  
-use_ok 'Module::Libs';
  5
+use_ok 'Project::Libs';
6 6
 
7 7
 done_testing;
6  t/find_inc.t
@@ -3,10 +3,10 @@ use warnings;
3 3
 use FindBin;
4 4
 use File::Spec;
5 5
 use Test::More;
6  
-use Module::Libs;
  6
+use Project::Libs;
7 7
 
8 8
 subtest 'find_inc' => sub {
9  
-    my @submodules = Module::Libs::find_inc($FindBin::Bin, [qw(extlib)], ());
  9
+    my @submodules = Project::Libs::find_inc($FindBin::Bin, [qw(extlib)], ());
10 10
     is_deeply \@submodules, [
11 11
         File::Spec->catfile($FindBin::Bin, 'extlib'),
12 12
         File::Spec->catfile($FindBin::Bin, 'modules/Plack/lib'),
@@ -18,7 +18,7 @@ subtest 'find_inc' => sub {
18 18
 my $gitmodules = "$FindBin::Bin/.gitmodules";
19 19
 
20 20
 subtest 'find_git_submodules' => sub {
21  
-    my @submodules = Module::Libs::find_git_submodules(
  21
+    my @submodules = Project::Libs::find_git_submodules(
22 22
         $FindBin::Bin,
23 23
         File::Spec->catfile($FindBin::Bin, '.gitmodules'),
24 24
     );

0 notes on commit 2ff143d

Please sign in to comment.
Something went wrong with that request. Please try again.