forked from masak/proto
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Initial work on Dist::Source base class and GitHub dist source
- Loading branch information
1 parent
4ec675f
commit 107e84a
Showing
5 changed files
with
151 additions
and
5 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
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
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
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,63 @@ | ||
| package DbBuilder::Dist::Source; | ||
|
|
||
| use strictures 2; | ||
|
|
||
| use JSON::Meth qw/$json/; | ||
| use Mojo::UserAgent; | ||
| use Try::Tiny; | ||
| use Types::Standard qw/Str/; | ||
|
|
||
| use DbBuilder::Log; | ||
|
|
||
| use Moo; | ||
| use namespace::clean; | ||
|
|
||
| has _logos_dir => ( | ||
| init_arg => 'logos_dir', | ||
| is => 'ro', | ||
| isa => Str, | ||
| required => 1, | ||
| ); | ||
|
|
||
| has _meta_url => ( | ||
| init_arg => 'meta_url', | ||
| is => 'ro', | ||
| isa => Str, | ||
| required => 1, | ||
| ); | ||
|
|
||
| sub _download_meta { | ||
| my $self = shift; | ||
| my $url = $self->_meta_url; | ||
|
|
||
| log info => "Downloading META file from $url"; | ||
| my $tx = Mojo::UserAgent->new( max_redirects => 10 )->get( $url ); | ||
|
|
||
| if ( $tx->success ) { return $tx->res->body } | ||
| else { | ||
| my $err = $tx->error; | ||
| log error => "$err->{code} response: $err->{message}" | ||
| if $err->{code}; | ||
| log error => "Connection error: $err->{message}"; | ||
| } | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| sub _parse_meta { | ||
| my ( $self, $data ) = @_; | ||
|
|
||
| log info => 'Parsing META file'; | ||
| eval { $data or die "No data to parse\n"; $data->$json }; | ||
| if ( $@ ) { log error => "Failed to parse: JSON error: $@"; return; } | ||
|
|
||
| length $json->{ $_ } or log warn => "Required `$_` field is missing" | ||
| for qw/perl name version description provides/; | ||
|
|
||
| return $json; | ||
| } | ||
|
|
||
| sub load { ... } | ||
| sub re { ... } | ||
|
|
||
| 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,16 @@ | ||
| package DbBuilder::Dist::Source::GitHub; | ||
|
|
||
| use strictures 2; | ||
| use base 'DbBuilder::Dist::Source'; | ||
|
|
||
| use DbBuilder::Log; | ||
|
|
||
| use Moo; | ||
| use namespace::clean; | ||
|
|
||
| sub re { qr{^https?://\Qraw.githubusercontent.com\Q}i } | ||
| sub load { | ||
| my $self = shift; | ||
|
|
||
| my $dist = $self->_parse_meta( $self->_download_meta ); | ||
| } |