Adapter-Async
view release on metacpan or search on metacpan
lib/Adapter/Async/OrderedList.pm view on Meta::CPAN
sub push {
my ($self, $data) = @_;
my $f;
$f = $self->count->then(sub {
my $count = shift;
$self->splice($count, 0, $data)->transform(
done => sub {
($count, @_)
}
);
})->on_ready(sub { undef $f });
$f
}
=head2 unshift
Inserts data at the start of the list.
=cut
sub unshift {
lib/Adapter/Async/OrderedList.pm view on Meta::CPAN
Removes the last element from the list, will resolve with the value.
=cut
sub pop {
my ($self, $data) = @_;
my $f;
$f = $self->count->then(sub {
$self->splice(shift() - 1, 1)
})->on_ready(sub { undef $f });
$f
}
=head2 shift
Removes the first element from the list, will resolve with the value.
=cut
sub shift {
lib/Adapter/Async/OrderedList.pm view on Meta::CPAN
sub all {
my ($self, %args) = @_;
my $f;
$f = $self->count->then(sub {
my ($count) = @_;
return Future->wrap([]) unless $count;
$self->get(
%args,
items => [0..$count-1],
)
})->on_ready(sub { undef $f });
$f
}
1;
__END__
=head1 AUTHOR
Tom Molesworth <TEAM@cpan.org>
lib/Adapter/Async/UnorderedMap.pm view on Meta::CPAN
sub all {
my ($self, %args) = @_;
my $f;
$f = $self->count->then(sub {
my ($count) = @_;
return Future->wrap([]) unless $count;
$self->get(
%args,
items => [0..$count-1],
)
})->on_ready(sub { undef $f });
$f
}
1;
__END__
=head1 AUTHOR
Tom Molesworth <TEAM@cpan.org>
t/00-report-prereqs.t view on Meta::CPAN
# This test was generated by Dist::Zilla::Plugin::Test::ReportPrereqs 0.025
use Test::More tests => 1;
use ExtUtils::MakeMaker;
use File::Spec;
# from $version::LAX
my $lax_version_re =
qr/(?: undef | (?: (?:[0-9]+) (?: \. | (?:\.[0-9]+) (?:_[0-9]+)? )?
|
(?:\.[0-9]+) (?:_[0-9]+)?
) | (?:
v (?:[0-9]+) (?: (?:\.[0-9]+)+ (?:_[0-9]+)? )?
|
(?:[0-9]+)? (?:\.[0-9]+){2,} (?:_[0-9]+)?
)
)/x;
# hide optional CPAN::Meta modules from prereq scanner
t/00-report-prereqs.t view on Meta::CPAN
for my $mod ( sort keys %{ $req_hash->{$phase}{$type} } ) {
next if $mod eq 'perl';
next if grep { $_ eq $mod } @exclude;
my $file = $mod;
$file =~ s{::}{/}g;
$file .= ".pm";
my ($prefix) = grep { -e File::Spec->catfile($_, $file) } @INC;
my $want = $req_hash->{$phase}{$type}{$mod};
$want = "undef" unless defined $want;
$want = "any" if !$want && $want == 0;
my $req_string = $want eq 'any' ? 'any version required' : "version '$want' required";
if ($prefix) {
my $have = MM->parse_version( File::Spec->catfile($prefix, $file) );
$have = "undef" unless defined $have;
push @reports, [$mod, $want, $have];
if ( $DO_VERIFY_PREREQS && $HAS_CPAN_META && $type eq 'requires' ) {
if ( $have !~ /\A$lax_version_re\z/ ) {
push @dep_errors, "$mod version '$have' cannot be parsed ($req_string)";
}
elsif ( ! $full_prereqs->requirements_for( $phase, $type )->accepts_module( $mod => $have ) ) {
push @dep_errors, "$mod version '$have' is not in required range '$want'";
}
}
splice => sub {
my ($ev, $idx, $len, $data) = @_;
is($idx, 0, 'splice event for insert had expected index');
is($len, 0, 'zero length');
is_deeply($data, ['x'], 'and our expected data');
$ev->unsubscribe;
}
);
is(exception {
$array->insert(0, ['x'])->get
}, undef, 'can insert item');
is($array->count->get, 1, 'now have one item');
is_deeply($array->get(
items => [0],
on_item => sub {
my ($idx, $item) = @_;
is($item, 'x', 'had expected item in callback');
}
)->get, ['x'], 'now have one item');
# Now for an append
splice => sub {
my ($ev, $idx, $len, $data) = @_;
is($idx, 1, 'splice event for append had expected index');
is($len, 0, 'zero length');
is_deeply($data, [qw(y z)], 'and our expected data');
$ev->unsubscribe;
}
);
is(exception {
$array->append(0, [qw(y z)])->get
}, undef, 'can append two more items');
is($array->count->get, 3, 'count is now 3');
{
my @expected = qw(x y z);
is_deeply($array->get(
items => [0..2],
on_item => sub {
my ($idx, $item) = @_;
is($item, splice(@expected, $idx, 1, undef), "had expected item $idx in callback");
}
)->get, [qw(x y z)], 'have our 3 items');
is_deeply(\@expected, [(undef) x 3], 'callback fired for all expected items');
}
# now we move
$array->bus->subscribe_to_event(
move => sub {
my ($ev, $idx, $len, $offset) = @_;
is($idx, 2, 'move event had expected index');
is($len, 1, 'correct length');
is($offset, -1, 'correct offset');
$ev->unsubscribe;
}
);
is(exception {
$array->move(2, 1, -1)->get
}, undef, 'can move last element back by one');
is($array->count->get, 3, 'count unchanged');
is_deeply($array->get(
items => [0..2],
)->get, [qw(x z y)], 'elements were reordered');
# and move in the other direction
$array->bus->subscribe_to_event(
move => sub {
my ($ev, $idx, $len, $offset) = @_;
is($idx, 0, 'move event had expected index');
is($len, 1, 'correct length');
is($offset, 1, 'correct offset');
$ev->unsubscribe;
}
);
is(exception {
$array->move(0, 1, 1)->get
}, undef, 'can move first element forward by one');
is($array->count->get, 3, 'count unchanged');
is_deeply($array->get(
items => [0..2],
)->get, [qw(z x y)], 'elements were reordered');
# and reorder back to original
is(exception {
$array->move(0, 1, 2)->get
}, undef, 'can move last element back to original place');
is($array->count->get, 3, 'count unchanged');
is_deeply($array->get(
items => [0..2],
)->get, [qw(x y z)], 'elements back in original order');
is(exception {
$array->clear->get
}, undef, 'can clear');
is($array->count->get, 0, 'count now zero');
{
my $modified = 0;
$array->bus->subscribe_to_event(
modify => sub {
my ($ev, $idx, $data) = @_;
is($idx, 2, 'modify event had expected index');
is($data, 'x', 'correct value');
++$modified;
$ev->unsubscribe;
}
);
is(exception {
$array->push([qw(a b c d)])->get;
}, undef, 'can push');
is($array->count->get, 4, 'count now 4');
is($modified, 0, 'not yet modified');
is(exception {
$array->modify(2, 'x')->get;
}, undef, 'can modify');
is($modified, 1, 'was modified');
}
{ # push
$array->clear->get;
my $modified = 0;
is(exception {
$array->push([$_])->get for qw(a b c d);
}, undef, 'can push');
is($array->count->get, 4, 'count now 4');
is_deeply($array->get(
items => [0..3],
)->get, [qw(a b c d)], 'elements were in the right order');
}
{ # find_idx
is(exception { $array->clear->get }, undef, 'clear array');
my @items = (qw(a b c d));
like(exception {
note "* had $_" for Future->needs_all(
map $array->find_idx($_), @items
)->get;
}, qr/not found/, 'no entries found yet');
is(exception {
$array->push([$_])->get for @items;
}, undef, 'can push');
is($array->count->get, 0 + @items, 'count now ' . @items);
is(exception {
my $idx = 0;
is($array->find_idx($_)->get, $idx++, "found at the right index") for @items;
}, undef, 'find_idx is happy now');
is_deeply($array->get(
items => [0..3],
)->get, [qw(a b c d)], 'elements were in the right order');
}
{ # find_idx
is(exception { $array->clear->get }, undef, 'clear array');
my @items = (qw(a b c d));
is(exception {
(fmap0 {
my $item = shift;
$array->find_insert_pos($item)->then(sub {
my ($idx) = @_;
ok(defined($idx), 'have some sort of value');
$array->insert($idx, [ $item ])
})
} foreach => [ @items ])->get;
}, undef, 'can populate via ->find_insert_pos');
is($array->count->get, 0 + @items, 'count now ' . @items);
is_deeply($array->get(
items => [0..3],
)->get, [qw(a b c d)], 'elements were in the right order');
is(exception {
my $idx = 0;
is($array->find_idx($_)->get, $idx++, "found at the right index") for @items;
}, undef, 'find_idx is happy now');
is(exception {
my $idx = 0;
is($array->find_insert_pos($_)->get, $idx++, "found at the right index") for @items;
}, undef, 'find_insert_pos is also happy');
}
done_testing;
( run in 1.716 second using v1.01-cache-2.11-cpan-d80b1682f3f )