Myriad
view release on metacpan or search on metacpan
lib/Myriad/Class.pm view on Meta::CPAN
This also makes available a L<Log::Any> instance in the C<$log> package variable,
and for L<OpenTracing::Any> support you get C<$tracer> as an L<OpenTracing::Tracer>
instance.
It's very likely that future versions will bring in new functionality or
enable/disable a different featureset. This behaviour will be controlled through
version tags:
use Myriad::Class qw(:v1);
with the default being C<:v1>.
=cut
use Object::Pad;
use Object::Pad qw(:experimental(mop));
no indirect qw(fatal);
no multidimensional;
no bareword::filehandles;
use mro;
use experimental qw(signatures);
use curry;
use Future::AsyncAwait;
use Syntax::Keyword::Try;
use Syntax::Keyword::Dynamically;
use Syntax::Keyword::Defer;
use Syntax::Keyword::Match;
use Syntax::Operator::Equ;
use Scalar::Util;
use List::Util;
use List::Keywords;
use Future::Utils;
use Module::Load ();
use JSON::MaybeUTF8;
use Unicode::UTF8;
use Heap;
use IO::Async::Notifier;
use Log::Any qw($log);
use OpenTracing::Any qw($tracer);
use Metrics::Any;
sub import {
my $called_on = shift;
# Unused, but we'll support it for now.
my $version = 1;
if(@_ and $_[0] =~ /^:v([0-9]+)/) {
$version = $1;
shift;
}
my %args = @_;
my $class = __PACKAGE__;
my $pkg = $args{target} // caller(0);
# Apply core syntax and rules
strict->import;
warnings->import;
utf8->import;
# We want mostly the 5.26 featureset, but since that includes `say` and `switch`
# we need to customise the list somewhat
feature->import(qw(
bitwise
current_sub
evalbytes
fc
postderef_qq
state
unicode_eval
unicode_strings
));
# Indirect syntax is problematic due to `unknown_sub { ... }` compiling and running
# the block without complaint, and only failing at runtime *after* the code has
# executed once - particularly unfortunate with try/catch
indirect->unimport(qw(fatal));
# Multidimensional array access - $x{3,4} - is usually a sign that someone wanted
# `@x{3,4}` or similar instead, so we disable this entirely
multidimensional->unimport;
# Plain STDIN/STDOUT/STDERR are still allowed, although hopefully never used by
# service code - new filehandles need to be lexical.
bareword::filehandles->unimport;
# This one's needed for nested scope, e.g. { package XX; use Myriad::Service; method xxx (%args) ... }
experimental->import('signatures');
# We don't really care about diamond inheritance, since microservices are expected
# to have minimal inheritance in the first place, but might as well have a standard
# decision to avoid surprises in future
mro::set_mro($pkg => 'c3');
# Helper functions which are used often enough to be valuable as a default
Scalar::Util->export($pkg => qw(refaddr blessed weaken));
List::Util->export($pkg => qw(min max sum0));
{
no strict 'refs';
*{$pkg . '::' . $_} = JSON::MaybeUTF8->can($_) for qw(
encode_json_text
encode_json_utf8
decode_json_text
decode_json_utf8
format_json_text
);
*{$pkg . '::' . $_} = Unicode::UTF8->can($_) for qw(
encode_utf8
decode_utf8
);
}
{
no strict 'refs';
*{$pkg . '::' . $_} = Future::Utils->can($_) for qw(
fmap_void
fmap_concat
fmap_scalar
fmap0
fmap1
( run in 2.691 seconds using v1.01-cache-2.11-cpan-75ffa21a3d4 )