view release on metacpan or search on metacpan
(1) You are permitted to use the Standard Version and create and use
Modified Versions for any purpose without restriction, provided that
you do not Distribute the Modified Version.
Permissions for Redistribution of the Standard Version
(2) You may Distribute verbatim copies of the Source form of the
Standard Version of this Package in any medium without restriction,
either gratis or for a Distributor Fee, provided that you duplicate
all of the original copyright notices and associated disclaimers. At
your discretion, such verbatim copies may or may not include a
Compiled form of the Package.
(3) You may apply any bug fixes, portability changes, and other
modifications made available from the Copyright Holder. The resulting
Package will still be considered the Standard Version, and as such
will be subject to the Original License.
Distribution of Modified Versions of the Package as Source
local/lib/perl5/Future.pm view on Meta::CPAN
If the future is not yet ready, adds a callback to be invoked if the future is
cancelled by the C<cancel> method. If the future is already ready, throws an
exception.
If the future is cancelled, the callbacks will be invoked in the reverse order
to that in which they were registered.
$on_cancel->( $future )
If passed another C<Future> instance, the passed instance will be cancelled
when the original future is cancelled. This method does nothing if the future
is already complete.
=cut
sub on_cancel
{
my $self = shift;
my ( $code ) = @_;
my $is_future = blessed( $code ) && $code->isa( "Future" );
local/lib/perl5/Future.pm view on Meta::CPAN
If the future is not yet ready, adds a callback to be invoked when the future
is ready. If the future is already ready, invokes it immediately.
In either case, the callback will be passed the future object itself. The
invoked code can then obtain the list of results by calling the C<get> method.
$on_ready->( $future )
If passed another C<Future> instance, the passed instance will have its
C<done>, C<fail> or C<cancel> methods invoked when the original future
completes successfully, fails, or is cancelled respectively.
Returns the C<$future>.
=cut
sub on_ready
{
my $self = shift;
my ( $code ) = @_;
local/lib/perl5/Future.pm view on Meta::CPAN
If the future is not yet ready, adds a callback to be invoked when the future
is ready, if it completes successfully. If the future completed successfully,
invokes it immediately. If it failed or was cancelled, it is not invoked at
all.
The callback will be passed the result passed to the C<done> method.
$on_done->( @result )
If passed another C<Future> instance, the passed instance will have its
C<done> method invoked when the original future completes successfully.
Returns the C<$future>.
=cut
sub on_done
{
my $self = shift;
my ( $code ) = @_;
local/lib/perl5/Future.pm view on Meta::CPAN
is ready, if it fails. If the future has already failed, invokes it
immediately. If it completed successfully or was cancelled, it is not invoked
at all.
The callback will be passed the exception and details passed to the C<fail>
method.
$on_fail->( $exception, @details )
If passed another C<Future> instance, the passed instance will have its
C<fail> method invoked when the original future fails.
To invoke a C<done> method on a future when another one fails, use a CODE
reference:
$future->on_fail( sub { $f->done( @_ ) } );
Returns the C<$future>.
=cut
local/lib/perl5/Future.pm view on Meta::CPAN
}, CB_SEQ_ONDONE|CB_SEQ_ONFAIL|CB_SELF );
}
=head2 then_with_f
$future = $f1->then_with_f( ... )
I<Since version 0.21.>
Returns a new sequencing C<Future> that behaves like C<then>, but also passes
the original future, C<$f1>, to any functions it invokes.
$f2 = $done_code->( $f1, @result )
$f2 = $catch_code->( $f1, $name, @other_details )
$f2 = $fail_code->( $f1, @details )
This is useful for conditional execution cases where the code block may just
return the same result of the original future. In this case it is more
efficient to return the original future itself.
=cut
sub then_with_f
{
my $self = shift;
my $done_code = shift;
my $fail_code = ( @_ % 2 ) ? pop : undef;
my @catch_list = @_;
local/lib/perl5/Future.pm view on Meta::CPAN
}
=head2 else_with_f
$future = $f1->else_with_f( \&code )
I<Since version 0.21.>
Returns a new sequencing C<Future> that runs the code if the first fails.
Identical to C<else>, except that the code reference will be passed both the
original future, C<$f1>, and its exception and details.
$f2 = $code->( $f1, $exception, @details )
This is useful for conditional execution cases where the code block may just
return the same result of the original future. In this case it is more
efficient to return the original future itself.
=cut
sub else_with_f
{
my $self = shift;
my ( $fail_code ) = @_;
return $self->_sequence( $fail_code, CB_SEQ_ONFAIL|CB_SELF|CB_RESULT );
}
local/lib/perl5/Future.pm view on Meta::CPAN
return $self->_sequence( \@failure, CB_SEQ_ONFAIL|CB_SEQ_IMFAIL );
}
=head2 catch_with_f
$future = $f1->catch_with_f( ... )
I<Since version 0.33.>
Returns a new sequencing C<Future> that behaves like C<catch>, but also passes
the original future, C<$f1>, to any functions it invokes.
=cut
sub catch_with_f
{
my $self = shift;
my $fail_code = ( @_ % 2 ) ? pop : undef;
my @catch_list = @_;
return $self->_sequence( $make_donecatchfail_sub->(
local/lib/perl5/Future.pm view on Meta::CPAN
return $self->_sequence( $code, CB_SEQ_ONDONE|CB_SEQ_ONFAIL|CB_SELF );
}
=head2 without_cancel
$future = $f1->without_cancel
I<Since version 0.30.>
Returns a new sequencing C<Future> that will complete with the success or
failure of the original future, but if cancelled, will not cancel the
original. This may be useful if the original future represents an operation
that is being shared among multiple sequences; cancelling one should not
prevent the others from running too.
=cut
sub without_cancel
{
my $self = shift;
my $new = $self->new;
local/lib/perl5/Future/Utils.pm view on Meta::CPAN
=head2 repeat+foreach
$future = repeat { CODE } foreach => ARRAY, otherwise => CODE
I<Since version 0.13.>
Calls the C<CODE> block once for each value obtained from the array, passing
in the value as the first argument (before the previous trial future). When
there are no more items left in the array, the C<otherwise> code is invoked
once and passed the last trial future, if there was one, or C<undef> if the
list was originally empty. The result of the eventual future will be the
result of the future returned from C<otherwise>.
The referenced array may be modified by this operation.
$trial_f = $code->( $item, $previous_trial_f )
$final_f = $otherwise->( $last_trial_f )
The C<otherwise> code is optional; if not supplied then the result of the
eventual future will simply be that of the last trial. If there was no trial,
because the C<foreach> list was already empty, then an immediate successful
local/lib/perl5/Future/Utils.pm view on Meta::CPAN
=head2 fmap_concat
$future = fmap_concat { CODE } ...
I<Since version 0.14.>
This version of C<fmap> expects each item future to return a list of zero or
more values, and the overall result will be the concatenation of all these
results. It acts like a future-based equivalent to Perl's C<map> operator.
The results are returned in the order of the original input values, not in the
order their futures complete in. Because of the intermediate storage of
C<ARRAY> references and final flattening operation used to implement this
behaviour, this function is slightly less efficient than C<fmap_scalar> or
C<fmap_void> in cases where item futures are expected only ever to return one,
or zero values, respectively.
This function is also available under the name of simply C<fmap> to emphasise
its similarity to perl's C<map> keyword.
=cut
local/lib/perl5/Future/Utils.pm view on Meta::CPAN
*fmap = \&fmap_concat;
=head2 fmap_scalar
$future = fmap_scalar { CODE } ...
I<Since version 0.14.>
This version of C<fmap> acts more like the C<map> functions found in Scheme or
Haskell; it expects that each item future returns only one value, and the
overall result will be a list containing these, in order of the original input
items. If an item future returns more than one value the others will be
discarded. If it returns no value, then C<undef> will be substituted in its
place so that the result list remains in correspondence with the input list.
This function is also available under the shorter name of C<fmap1>.
=cut
sub fmap_scalar(&@)
{
local/lib/perl5/IO/Async/ChildManager.pm view on Meta::CPAN
my %fds_refcount = %fd_in_use;
# To dup2() without clashes we might need to temporarily move some handles
my %dup_from;
my $max_fd = 0;
my $writepipe_clashes = 0;
if( @$setup ) {
# The writepipe might be in the way of a setup filedescriptor. If it
# is we'll have to dup2 it out of the way then close the original.
foreach my $i ( 0 .. $#$setup/2 ) {
my ( $key, $value ) = @$setup[$i*2, $i*2 + 1];
$key =~ m/^fd(\d+)$/ or next;
my $fd = $1;
$max_fd = $fd if $fd > $max_fd;
$writepipe_clashes = 1 if $fd == fileno $writepipe;
my ( $operation, @params ) = @$value;
local/lib/perl5/IO/Async/Loop.pm view on Meta::CPAN
or similar, without needing every module to be aware of the C<SSL> extension.
This functionality is generic and not limited to C<SSL>; other extensions may
also use it.
The following methods take an C<extensions> parameter:
$loop->connect
$loop->listen
If an extension C<listen> method is invoked, it will be passed a C<listener>
parameter even if one was not provided to the original C<< $loop->listen >>
call, and it will not receive any of the C<on_*> event callbacks. It should
use the C<acceptor> parameter on the C<listener> object.
=cut
=head1 STALL WATCHDOG
A well-behaved L<IO::Async> program should spend almost all of its time
blocked on input using the underlying C<IO::Async::Loop> instance. The stall
watchdog is an optional debugging feature to help detect CPU spinlocks and
local/lib/perl5/IO/Async/Notifier.pm view on Meta::CPAN
=head2 _remove_from_loop
$notifier->_remove_from_loop( $loop )
This method is called when the Notifier has been removed from a Loop; either
directly, or indirectly through being a child of a Notifier removed from the
loop.
This method may be used to undo the effects of any setup that the
C<_add_to_loop> method had originally done.
=cut
sub _remove_from_loop
{
# empty default
}
=head1 UTILITY METHODS
=cut
=head2 _capture_weakself
$mref = $notifier->_capture_weakself( $code )
Returns a new CODE ref which, when invoked, will invoke the originally-passed
ref, with additionally a reference to the Notifier as its first argument. The
Notifier reference is stored weakly in C<$mref>, so this CODE ref may be
stored in the Notifier itself without creating a cycle.
For example,
my $mref = $notifier->_capture_weakself( sub {
my ( $notifier, $arg ) = @_;
print "Notifier $notifier got argument $arg\n";
} );
local/lib/perl5/IO/Async/Notifier.pm view on Meta::CPAN
unshift @_, $self;
goto &$cv;
}
};
}
=head2 _replace_weakself
$mref = $notifier->_replace_weakself( $code )
Returns a new CODE ref which, when invoked, will invoke the originally-passed
ref, with a reference to the Notifier replacing its first argument. The
Notifier reference is stored weakly in C<$mref>, so this CODE ref may be
stored in the Notifier itself without creating a cycle.
For example,
my $mref = $notifier->_replace_weakself( sub {
my ( $notifier, $arg ) = @_;
print "Notifier $notifier got argument $arg\n";
} );
local/lib/perl5/IO/Async/Socket.pm view on Meta::CPAN
=head2 on_recv_error $errno
Optional. Invoked when the C<recv> method on the receiving handle fails.
=head2 on_send_error $errno
Optional. Invoked when the C<send> method on the sending handle fails.
The C<on_recv_error> and C<on_send_error> handlers are passed the value of
C<$!> at the time the error occured. (The C<$!> variable itself, by its
nature, may have changed from the original error by the time this handler
runs so it should always use the value passed in).
If an error occurs when the corresponding error callback is not supplied, and
there is not a subclass method for it, then the C<close> method is
called instead.
=head2 on_outgoing_empty
Optional. Invoked when the sending data buffer becomes empty.
local/lib/perl5/IO/Async/Stream.pm view on Meta::CPAN
records at the same time. See the examples at the end of this documentation
for more detail.
The second argument is a scalar indicating whether the stream has reported an
end-of-file (EOF) condition. A reference to the buffer is passed to the
handler in the usual way, so it may inspect data contained in it. Once the
handler returns a false value, it will not be called again, as the handle is
now at EOF and no more data can arrive.
The C<on_read> code may also dynamically replace itself with a new callback
by returning a CODE reference instead of C<0> or C<1>. The original callback
or method that the object first started with may be restored by returning
C<undef>. Whenever the callback is changed in this way, the new code is called
again; even if the read buffer is currently empty. See the examples at the end
of this documentation for more detail.
The C<push_on_read> method can be used to insert new, temporary handlers that
take precedence over the global C<on_read> handler. This event is only used if
there are no further pending handlers created by C<push_on_read>.
=head2 on_read_eof
local/lib/perl5/IO/Async/Stream.pm view on Meta::CPAN
=head2 on_read_error $errno
Optional. Invoked when the C<sysread> method on the read handle fails.
=head2 on_write_error $errno
Optional. Invoked when the C<syswrite> method on the write handle fails.
The C<on_read_error> and C<on_write_error> handlers are passed the value of
C<$!> at the time the error occured. (The C<$!> variable itself, by its
nature, may have changed from the original error by the time this handler
runs so it should always use the value passed in).
If an error occurs when the corresponding error callback is not supplied, and
there is not a handler for it, then the C<close> method is called instead.
=head2 on_read_high_watermark $length
=head2 on_read_low_watermark $length
Optional. Invoked when the read buffer grows larger than the high watermark
local/lib/perl5/IO/Async/Stream.pm view on Meta::CPAN
my $self = shift;
my ( $buffref, $eof ) = @_;
return 0 unless length $$buffref >= $length;
# Take and remove the data from the buffer
my $data = substr( $$buffref, 0, $length, "" );
print "Received a line $line with some data ($data)\n";
return undef; # Restore the original method
}
}
elsif( $$buffref =~ s/^LINE:(.*)\n// ) {
my $line = $1;
print "Received a line $line with no data\n";
return 1;
}
else {
print STDERR "Unrecognised input\n";
# Handle it somehow
}
}
In the case where trailing data is supplied, a new temporary C<on_read>
callback is provided in a closure. This closure captures the C<$length>
variable so it knows how much data to expect. It also captures the C<$line>
variable so it can use it in the event report. When this method has finished
reading the data, it reports the event, then restores the original method by
returning C<undef>.
=head1 SEE ALSO
=over 4
=item *
L<IO::Handle> - Supply object methods for I/O handles
local/lib/perl5/Module/Build/API.pod view on Meta::CPAN
code in the F<_build/prereqs> file, leave it as a static declaration
containing only strings and numbers. Similarly, do not alter the
structure of the internal C<< $self->{properties}{requires} >> (etc.)
data members, because that's where this data comes from.
=item current_action()
[version 0.28]
Returns the name of the currently-running action, such as "build" or
"test". This action is not necessarily the action that was originally
invoked by the user. For example, if the user invoked the "test"
action, current_action() would initially return "test". However,
action "test" depends on action "code", so current_action() will
return "code" while that dependency is being executed. Once that
action has completed, current_action() will again return "test".
If you need to know the name of the original action invoked by the
user, see L</invoked_action()> below.
=item depends_on(@actions)
[version 0.28]
Invokes the named action or list of actions in sequence. Using this
method is preferred to calling the action explicitly because it
performs some internal record-keeping, and it ensures that the same
action is not invoked multiple times (note: in future versions of
local/lib/perl5/Module/Build/API.pod view on Meta::CPAN
These types each correspond to the name of a directory in F<blib/>,
and the list usually includes items such as C<lib>, C<arch>, C<bin>,
C<script>, C<libdoc>, C<bindoc>, and if HTML documentation is to be
built, C<libhtml> and C<binhtml>. Other user-defined types may also
exist.
=item invoked_action()
[version 0.28]
This is the name of the original action invoked by the user. This
value is set when the user invokes F<Build.PL>, the F<Build> script,
or programmatically through the L<dispatch()|/"dispatch($action, %args)">
method. It does not change as sub-actions are executed as
dependencies are evaluated.
To get the name of the currently executing dependency, see
L</current_action()> above.
=item notes()
local/lib/perl5/Module/Build/Authoring.pod view on Meta::CPAN
requires => { Carp => 0 }
);
$build->create_build_script;
This is relatively straightforward, and is the best way to do things
if your My::Builder class contains lots of code. The
C<create_build_script()> method will ensure that the current value of
C<@INC> (including the C</nonstandard/library/path>) is propagated to
the Build script, so that My::Builder can be found when running build
actions. If you find that you need to C<chdir> into a different directories
in your subclass methods or actions, be sure to always return to the original
directory (available via the C<base_dir()> method) before returning control
to the parent class. This is important to avoid data serialization problems.
For very small additions, Module::Build provides a C<subclass()>
method that lets you subclass Module::Build more conveniently, without
creating a separate file for your module:
------ in Build.PL: ----------
#!/usr/bin/perl
local/lib/perl5/Module/Build/Authoring.pod view on Meta::CPAN
C<Foo::Bar::ConfigData> documentation, and the C<config_data>
script's documentation, for more information.
=head1 STARTING MODULE DEVELOPMENT
When starting development on a new module, it's rarely worth your time
to create a tree of all the files by hand. Some automatic
module-creators are available: the oldest is C<h2xs>, which has
shipped with perl itself for a long time. Its name reflects the fact
that modules were originally conceived of as a way to wrap up a C
library (thus the C<h> part) into perl extensions (thus the C<xs>
part).
These days, C<h2xs> has largely been superseded by modules like
C<ExtUtils::ModuleMaker>, and C<Module::Starter>. They have varying
degrees of support for C<Module::Build>.
=head1 AUTOMATION
local/lib/perl5/Module/Build/Base.pm view on Meta::CPAN
bin => $c->get('installvendorbin') || $c->get('installbin'),
script => $c->get('installvendorscript') ||
$c->get('installvendorbin') || $c->get('installscript'),
bindoc => $c->get('installvendorman1dir') || $bindoc,
libdoc => $c->get('installvendorman3dir') || $libdoc,
binhtml => $c->get('installvendorhtml1dir') || $binhtml,
libhtml => $c->get('installvendorhtml3dir') || $libhtml,
},
};
$p->{original_prefix} =
{
core => $c->get('installprefixexp') || $c->get('installprefix') ||
$c->get('prefixexp') || $c->get('prefix') || '',
site => $c->get('siteprefixexp'),
vendor => $c->get('usevendorprefix') ? $c->get('vendorprefixexp') : '',
};
$p->{original_prefix}{site} ||= $p->{original_prefix}{core};
# Note: you might be tempted to use $Config{installstyle} here
# instead of hard-coding lib/perl5, but that's been considered and
# (at least for now) rejected. `perldoc Config` has some wisdom
# about it.
$p->{install_base_relpaths} =
{
lib => ['lib', 'perl5'],
arch => ['lib', 'perl5', $arch],
bin => ['bin'],
local/lib/perl5/Module/Build/Base.pm view on Meta::CPAN
__PACKAGE__->add_property(prereq_action_types => \@prereq_action_types);
}
__PACKAGE__->add_property($_ => {}) for qw(
get_options
install_base_relpaths
install_path
install_sets
meta_add
meta_merge
original_prefix
prefix_relpaths
configure_requires
);
__PACKAGE__->add_property($_) for qw(
PL_files
autosplit
base_dir
bindoc_dirs
c_source
local/lib/perl5/Module/Build/Base.pm view on Meta::CPAN
# Try loading META.json or META.yml
if ( $self->try_require("CPAN::Meta", "2.142060") ) {
for my $file ( @metafiles ) {
next unless -f $file;
$meta_obj = eval { CPAN::Meta->load_file($file, { lazy_validation => 0 }) };
last if $meta_obj;
}
}
# maybe get a copy in spec v2 format (regardless of original source)
my $mymeta_obj;
if ($meta_obj) {
# if we have metadata, just update it
my %updated = (
%{ $meta_obj->as_struct({ version => 2.0 }) },
prereqs => $self->_normalize_prereqs,
dynamic_config => 0,
generated_by => "Module::Build version $Module::Build::VERSION",
);
local/lib/perl5/Module/Build/Base.pm view on Meta::CPAN
unless ( -d $htmldir ) {
File::Path::mkpath($htmldir, 0, oct(755))
or die "Couldn't mkdir $htmldir: $!";
}
my @rootdirs = ($type eq 'bin') ? qw(bin) :
$self->installdirs eq 'core' ? qw(lib) : qw(site lib);
my $podroot = $ENV{PERL_CORE}
? File::Basename::dirname($ENV{PERL_CORE})
: $self->original_prefix('core');
my $htmlroot = $self->install_sets('core')->{libhtml};
my $podpath;
unless (defined $self->args('html_links') and !$self->args('html_links')) {
my @podpath = ( (map { File::Spec->abs2rel($_ ,$podroot) } grep { -d }
( $self->install_sets('core', 'lib'), # lib
$self->install_sets('core', 'bin'), # bin
$self->install_sets('site', 'lib'), # site/lib
) ), File::Spec->rel2abs($self->blib) );
local/lib/perl5/Module/Build/Base.pm view on Meta::CPAN
return $map->{$dirs}{$key};
}
elsif ( defined $dirs ) {
return $map->{$dirs};
}
else {
croak "Can't determine installdirs for install_sets()";
}
}
sub original_prefix {
# Usage: original_prefix(), original_prefix('lib'),
# or original_prefix('lib' => $value);
my ($self, $key, $value) = @_;
# update property before merging with defaults
if ( @_ == 3 && defined $key) {
# $value can be undef; will mask default
$self->{properties}{original_prefix}{$key} = $value;
}
my $map = { $self->_merge_arglist(
$self->{properties}{original_prefix},
$self->_default_install_paths->{original_prefix}
)};
return $map unless defined $key;
return $map->{$key}
}
sub install_base_relpaths {
# Usage: install_base_relpaths(), install_base_relpaths('lib'),
# or install_base_relpaths('lib' => $value);
my $self = shift;
if ( @_ > 1 ) { # change values before merge
local/lib/perl5/Module/Build/Base.pm view on Meta::CPAN
}
# Translated from ExtUtils::MM_Any::init_INSTALL_from_PREFIX
sub prefix_relative {
my ($self, $type) = @_;
my $installdirs = $self->installdirs;
my $relpath = $self->install_sets($installdirs)->{$type};
return $self->_prefixify($relpath,
$self->original_prefix($installdirs),
$type,
);
}
# Translated from ExtUtils::MM_Unix::prefixify()
sub _prefixify {
my($self, $path, $sprefix, $type) = @_;
my $rprefix = $self->prefix;
$rprefix .= '/' if $sprefix =~ m|/$|;
local/lib/perl5/Sub/Uplevel.pm view on Meta::CPAN
#pod =back
#pod
#pod =head1 EXAMPLE
#pod
#pod The main reason I wrote this module is so I could write wrappers
#pod around functions and they wouldn't be aware they've been wrapped.
#pod
#pod use Sub::Uplevel;
#pod
#pod my $original_foo = \&foo;
#pod
#pod *foo = sub {
#pod my @output = uplevel 1, $original_foo;
#pod print "foo() returned: @output";
#pod return @output;
#pod };
#pod
#pod If this code frightens you B<you should not use this module.>
#pod
#pod
#pod =head1 BUGS and CAVEATS
#pod
#pod Well, the bad news is uplevel() is about 5 times slower than a normal
local/lib/perl5/Sub/Uplevel.pm view on Meta::CPAN
=back
=head1 EXAMPLE
The main reason I wrote this module is so I could write wrappers
around functions and they wouldn't be aware they've been wrapped.
use Sub::Uplevel;
my $original_foo = \&foo;
*foo = sub {
my @output = uplevel 1, $original_foo;
print "foo() returned: @output";
return @output;
};
If this code frightens you B<you should not use this module.>
=head1 BUGS and CAVEATS
Well, the bad news is uplevel() is about 5 times slower than a normal
function call. XS implementation anyone? It also slows down every invocation