A Changelog => Changelog +2 -0
@@ 0,0 1,2 @@
+0.001 2021-07-25
+ - Initial release
M dist.ini => dist.ini +0 -1
@@ 24,7 24,6 @@ Path::Tiny = 0
[Prereqs / DevelopRequires]
Test2::V0 = 0
-Test2::Tools::Exception = 0
File::Spec = 0
[@Filter]
M lib/Lang/Go/Mod.pm => lib/Lang/Go/Mod.pm +50 -6
@@ 1,3 1,8 @@
+# You may distribute under the terms of either the GNU General Public License
+# or the Artistic License (the same terms as Perl itself)
+#
+# (C) Brad Clawsie, 2021 -- brad.clawsie@gmail.com
+
package Lang::Go::Mod;
use warnings;
use strict;
@@ 6,7 11,7 @@ use English qw(-no_match_vars);
use Exporter qw(import);
use Path::Tiny qw(path);
-# ABSTRACT: Parse and model go.mod files
+# ABSTRACT: parse and model go.mod files
our $VERSION = '0.001';
our $AUTHORITY = 'cpan:bclawsie';
@@ 133,19 138,58 @@ __END__
=head1 NAME
-Lang::Go::Mod
+C<Lang::Go::Mod> - parse and model go.mod files
=head1 SYNOPSIS
-Parse and model go.mod files.
+ # $ cat go.mod
+ # module github.com/example/my-project
+ # go 1.16
+ # exclude (
+ # example.com/whatmodule v1.4.0
+ # )
+ # replace (
+ # github.com/example/my-project/pkg/app => ./pkg/app
+ # )
+ # require (
+ # golang.org/x/sys v0.0.0-20210510120138-977fb7262007 // indirect
+ # )
+
+ use Lang::Go::Mod qw(read_go_mod parse_go_mod);
+
+ my $go_mod_path = '/path/to/go.mod';
+
+ # read and parse the go.mod file
+ # all errors croak, so wrap this in your favorite variant of try/catch
+ # to gracefully manage errors
+ my $m = read_go_mod($go_mod_path);
+ # use parse_go_mod to parse the go.mod content if it is already in a scalar
+
+ print $m->{module}; # github.com/example/my-project
+ print $m->{go}; # 1.16
+ print $m->{exclude}->{'example.com/whatmodule'}; # [v1.4.0]
+ print $m->{replace}->{'github.com/example/my-project/pkg/app'}; # ./pkg/app
+ print $m->{'require'}->{'golang.org/x/sys'}; # v0.0.0-20210510120138-977fb7262007
=head1 DESCRIPTION
-Parse and model go.mod files.
+This module creates a hash representation of a C<go.mod> file.
+Both single line and multiline C<exclude>, C<replace>, and C<require>
+sections are supported. For a full reference of the C<go.mod> format, see
+
+L<https://golang.org/doc/modules/gomod-ref>
+
+=head1 EXPORTED METHODS
+
+=head2 C<read_go_mod>
+
+Given a full filepath for a C<go.mod> file, read it, parse it and
+return the hash representation of the contents. All errors C<croak>.
-=head1 REFERENCE
+=head2 C<parse_go_mod>
-https://golang.org/doc/modules/gomod-ref
+Given a scalar of the contents of a C<go.mod> file, parse it and
+return the hash representation of the contents. All errors C<croak>.
=head1 LICENSE
M t/01-sample.t => t/01-sample.t +0 -1
@@ 1,7 1,6 @@
package main;
use File::Spec;
use Test2::V0;
-use Test2::Tools::Exception;
use Lang::Go::Mod qw(read_go_mod);
my $samples_path = File::Spec->catfile( File::Spec->curdir(), 't', 'samples' );
M t/02-fail.t => t/02-fail.t +0 -1
@@ 1,7 1,6 @@
package main;
use File::Spec;
use Test2::V0;
-use Test2::Tools::Exception;
use Lang::Go::Mod qw(parse_go_mod);
my $go_version = 'go 1.16';
A t/03-kwalitee.t => t/03-kwalitee.t +12 -0
@@ 0,0 1,12 @@
+# use Test::More;
+use Test2::V0;
+use strict;
+use warnings;
+BEGIN {
+ plan skip_all => 'these tests are for release candidate testing'
+ unless $ENV{RELEASE_TESTING};
+}
+
+use Test::Kwalitee 'kwalitee_ok';
+kwalitee_ok();
+done_testing;