Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate Dist::Zilla with Babble #716

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion dist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ App::cpanminus = 0
PPI::XS = 0

[Prereqs]
perl = v5.20.0
perl = v5.14.0

parent = 0 ; used by the AutoPrereq test corpus

Expand Down Expand Up @@ -87,3 +87,13 @@ Dist::Zilla::Plugin::NameFromDirectory = <= 0.03
:version = 0.017
conflicts_module = Moose::Conflicts
conflicts_module = Module::Runtime::Conflicts

[Babble]
plugin = ::CoreSignatures
plugin = ::PostfixDeref

[Substitute / Pragmas]
file = lib/Dist/Zilla/Pragmas.pm
mode = whole
code = s/use v5.20.0/use v5.14.0/;
code = s/^#begin babble.*?^#end babble\n//gsm;
8 changes: 5 additions & 3 deletions lib/Dist/Zilla.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use Dist::Zilla::Path;
use List::Util 1.33 qw(first none);
use Software::License 0.104001; # ->program
use String::RewritePrefix;
use Try::Tiny;
use Feature::Compat::Try;

use Dist::Zilla::Prereqs;
use Dist::Zilla::File::OnDisk;
Expand Down Expand Up @@ -469,8 +469,10 @@ has authors => (
return $stash->authors;
}

my $author = try { $self->copyright_holder };
return [ $author ] if length $author;
try {
my $author = $self->copyright_holder;
return [ $author ] if length $author;
} catch ($e) { }

$self->log_fatal(
"No %User stash and no copyright holder;",
Expand Down
16 changes: 8 additions & 8 deletions lib/Dist/Zilla/App.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use Dist::Zilla::Pragmas;
use App::Cmd::Setup 0.330 -app; # better compilation error detection

use Carp ();
use Try::Tiny;
use Feature::Compat::Try;
use Scalar::Util 'blessed';

use namespace::autoclean;

Expand Down Expand Up @@ -63,8 +64,7 @@ sub _build_global_stashes {
});

my $seq = $reader->read_config($config_base, { assembler => $assembler });
} catch {
my $e = $_;
} catch($e) {
if (eval { $e->isa('Config::MVP::Error') and $e->ident eq 'package not installed' }) {
my $package = $e->package;

Expand All @@ -88,7 +88,7 @@ and deleting any [!new] stanza. You can also delete the existing file and run
"dzil setup"
END_DIE
}
};
}

return $stash_registry;
}
Expand Down Expand Up @@ -141,11 +141,11 @@ sub zilla {
chrome => $self->chrome,
_global_stashes => $self->_build_global_stashes,
});
} catch {
die $_ unless try { $_->isa('Config::MVP::Error') }
&& $_->ident =~ /no viable config/;
} catch($e) {
die $e unless blessed($e) && $e->isa('Config::MVP::Error')
&& $e->ident =~ /no viable config/;
$self->chrome->logger->log_fatal("no configuration (e.g, dist.ini) found");
};
}

$zilla->logger->set_debug($verbose ? 1 : 0);

Expand Down
23 changes: 10 additions & 13 deletions lib/Dist/Zilla/Dist/Builder.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ use Dist::Zilla::Types qw(Path);

use File::pushd ();
use Dist::Zilla::Path; # because more Path::* is better, eh?
use Try::Tiny;
use Feature::Compat::Try;
use List::Util 1.45 'uniq';
use Scalar::Util 'blessed';
use Module::Runtime 'require_module';

use namespace::autoclean;
Expand Down Expand Up @@ -285,22 +286,20 @@ sub _load_config {
if $arg->{_global_stashes};
}

my $seq;
try {
$seq = $config_class->read_config(
return $config_class->read_config(
$root->child('dist'),
{
assembler => $assembler
},
);
} catch {
die $_ unless try {
$_->isa('Config::MVP::Error')
and $_->ident eq 'package not installed'
};
} catch($e) {
die $e unless
blessed($e) and $e->isa('Config::MVP::Error')
and $e->ident eq 'package not installed';

my $package = $_->package;
my $bundle = $_->section_name =~ m{^@(?!.*/)} ? ' bundle' : '';
my $package = $e->package;
my $bundle = $e->section_name =~ m{^@(?!.*/)} ? ' bundle' : '';

die <<"END_DIE";
Required plugin$bundle $package isn't installed.
Expand All @@ -312,9 +311,7 @@ You can pipe the list to your CPAN client to install or update them:

END_DIE

};

return $seq;
}
}

=method build_in
Expand Down
11 changes: 5 additions & 6 deletions lib/Dist/Zilla/Plugin/MetaYAML.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ with 'Dist::Zilla::Role::FileGatherer';

use Dist::Zilla::Pragmas;

use Try::Tiny;
use Feature::Compat::Try;
use namespace::autoclean;

=head1 DESCRIPTION
Expand Down Expand Up @@ -59,13 +59,12 @@ sub gather_files {
$output->{x_serialization_backend} = sprintf '%s version %s',
'YAML::Tiny', YAML::Tiny->VERSION;

my $yaml = try {
YAML::Tiny->new($output)->write_string; # text!
try {
return YAML::Tiny->new($output)->write_string; # text!
}
catch {
catch($e) {
$self->log_fatal("Could not create YAML string: " . YAML::Tiny->errstr)
};
return $yaml;
}
},
});

Expand Down
21 changes: 10 additions & 11 deletions lib/Dist/Zilla/Plugin/UploadToCPAN.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use File::Spec;
use Moose::Util::TypeConstraints;
use Scalar::Util qw(weaken);
use Dist::Zilla::Util;
use Try::Tiny;
use Feature::Compat::Try;

use namespace::autoclean;

Expand Down Expand Up @@ -188,13 +188,12 @@ has pause_cfg => (
$file = File::Spec->catfile($self->pause_cfg_dir, $file)
unless File::Spec->file_name_is_absolute($file);
return {} unless -e $file && -r _;
my $cfg = try {
CPAN::Uploader->read_config_file($file)
} catch {
$self->log("Couldn't load credentials from '$file': $_");
{};
};
return $cfg;
try {
return CPAN::Uploader->read_config_file($file)
} catch($e) {
$self->log("Couldn't load credentials from '$file': $e");
return {};
}
},
);

Expand Down Expand Up @@ -292,9 +291,9 @@ sub before_release {
die unless length $self->$attr;
}
undef $problem;
};

$self->log_fatal(['You need to supply a %s', $problem]) if $problem;
} catch($e) {
$self->log_fatal(['You need to supply a %s', $problem]) if $problem;
}
}

sub release {
Expand Down
2 changes: 2 additions & 0 deletions lib/Dist/Zilla/Pragmas.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ sub import {
feature->import(':5.20');
feature->unimport('switch');

#begin babble
experimental->import(qw(
lexical_subs
postderef
postderef_qq
signatures
));
#end babble

feature->unimport('multidimensional') if $] >= 5.034;
}
Expand Down
48 changes: 24 additions & 24 deletions lib/Dist/Zilla/Role/File.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use Dist::Zilla::Pragmas;

use Dist::Zilla::Types qw(_Filename);
use Moose::Util::TypeConstraints;
use Try::Tiny;
use Feature::Compat::Try;

use namespace::autoclean;

Expand Down Expand Up @@ -128,10 +128,8 @@ sub _encode {
}
else {
require Encode;
my $bytes =
try { Encode::encode($enc, $text, Encode::FB_CROAK()) }
catch { $self->_throw("encode $enc" => $_) };
return $bytes;
try { return Encode::encode($enc, $text, Encode::FB_CROAK()) }
catch($e) { $self->_throw("encode $enc" => $e) }
}
}

Expand All @@ -143,25 +141,27 @@ sub _decode {
}
else {
require Encode;
my $text =
try { Encode::decode($enc, $bytes, Encode::FB_CROAK()) }
catch { $self->_throw("decode $enc" => $_) };

# Okay, look, buddy… If you're using a BOM on UTF-8, that's fine. You can
# use it. You're just not going to get it back. If we don't do this, the
# sequence of events will be:
# * read file from UTF-8-BOM file on disk
# * end up with FEFF as first character of file
# * pass file content to PPI
# * PPI blows up
#
# I'm not going to try to account for the BOM and add it back. It's awful!
#
# Meanwhile, if you're using UTF-16, you can get the BOM handled by picking
# the right encoding type, I think. -- rjbs, 2016-04-24
$enc =~ /^utf-?8$/i && $text =~ s/\A\x{FEFF}//;

return $text;
try {
my $text = Encode::decode($enc, $bytes, Encode::FB_CROAK());

# Okay, look, buddy… If you're using a BOM on UTF-8, that's fine. You can
# use it. You're just not going to get it back. If we don't do this, the
# sequence of events will be:
# * read file from UTF-8-BOM file on disk
# * end up with FEFF as first character of file
# * pass file content to PPI
# * PPI blows up
#
# I'm not going to try to account for the BOM and add it back. It's awful!
#
# Meanwhile, if you're using UTF-16, you can get the BOM handled by picking
# the right encoding type, I think. -- rjbs, 2016-04-24
$enc =~ /^utf-?8$/i && $text =~ s/\A\x{FEFF}//;

return $text;
} catch($e) {
$self->_throw("decode $enc" => $e)
}
}
}

Expand Down
1 change: 0 additions & 1 deletion t/compile.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use warnings;
use Test::More;

use File::Find::Rule;
use Try::Tiny;

my @files = File::Find::Rule->name('*.pm')->in('lib');
plan tests => @files - 1;
Expand Down