view release on metacpan or search on metacpan
New dependencies:
* List::BinarySearch is now required, rather than optional
Features:
* ->find_idx and ->find_insert_pos on arrays
0.017 2015-03-06 16:37:04+00:00 Europe/London
No new features.
Bugs fixed:
* ->push on an ::OrderedList now adds to the end, rather than the start
Test fixes:
* Missed a defer_methods override in model.t, was failing without Check::UnitCheck
0.016 2015-03-06 16:15:29+00:00 Europe/London
0.015 2015-03-06 15:11:54+00:00 Europe/London
No new features.
Dependency fixes:
you changed the files and the date of any change; and
b) cause the whole of any work that you distribute or publish, that
in whole or in part contains the Program or any part thereof, either
with or without modifications, to be licensed at no charge to all
third parties under the terms of this General Public License (except
that you may choose to grant warranty protection to some or all
third parties, at your option).
c) If the modified program normally reads commands interactively when
run, you must cause it, when started running for such interactive use
in the simplest and most usual way, to print or display an
announcement including an appropriate copyright notice and a notice
that there is no warranty (or else, saying that you provide a
warranty) and that users may redistribute the program under these
conditions, and telling the user how to view a copy of this General
Public License.
d) You may charge a fee for the physical act of transferring a
copy, and you may at your option offer warranty protection in
exchange for a fee.
END OF TERMS AND CONDITIONS
Appendix: How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to humanity, the best way to achieve this is to make it
free software which everyone can redistribute and change under these
terms.
To do so, attach the following notices to the program. It is safest to
attach them to the start of each source file to most effectively convey
the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 19yy <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19xx name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the
appropriate parts of the General Public License. Of course, the
commands you use may be called something other than `show w' and `show
c'; they could even be mouse-clicks or menu items--whatever suits your
lib/Adapter/Async/OrderedList.pm view on Meta::CPAN
=item * move - an existing element moves to a new position (some adapters may not be able to differentiate between this and splice: if in doubt, use splice instead, don't report as a move unless it's guaranteed to be existing items)
index, length, offset (+/-)
=back
The view raises these:
=over 4
=item * visible - indicates visibility of one or more items. change events will start being sent for these items.
visible => [1,2,3,4,5,6]
Filters may result in a list with gaps:
visible => [1,3,4,8,9,10]
Note that "visible" means "the user is able to see this data", so they'd be a single page of data rather than the entire set when no filters are applied. Visibility changes often - scrolling will trigger a visible/hidden pair for example.
Also note that ->get may be called on any element, regardless of visibility - prefetching is one common example here.
lib/Adapter/Async/OrderedList.pm view on Meta::CPAN
done => sub {
($count, @_)
}
);
})->on_ready(sub { undef $f });
$f
}
=head2 unshift
Inserts data at the start of the list.
=cut
sub unshift {
my ($self, $data) = @_;
$self->splice(0, 0, $data)
}
=head2 pop
lib/Adapter/Async/OrderedList.pod view on Meta::CPAN
=item * move - an existing element moves to a new position (some adapters may not be able to differentiate between this and splice: if in doubt, use splice instead, don't report as a move unless it's guaranteed to be existing items)
index, length, offset (+/-)
=back
The view raises these:
=over 4
=item * visible - indicates visibility of one or more items. change events will start being sent for these items.
visible => [1,2,3,4,5,6]
Filters may result in a list with gaps:
visible => [1,3,4,8,9,10]
Note that "visible" means "the user is able to see this data", so they'd be a single page of data rather than the entire set when no filters are applied. Visibility changes often - scrolling will trigger a visible/hidden pair for example.
Also note that ->get may be called on any element, regardless of visibility - prefetching is one common example here.
lib/Adapter/Async/OrderedList.pod view on Meta::CPAN
Appends data after the given position.
$adapter->append(3, [...])
=head2 push
Appends data to the end of the list.
=head2 unshift
Inserts data at the start of the list.
=head2 pop
Removes the last element from the list, will resolve with the value.
=head2 shift
Removes the first element from the list, will resolve with the value.
=head2 all
lib/Adapter/Async/OrderedList/Array.pm view on Meta::CPAN
$self->{data}[$idx] = $data;
$self->bus->invoke_event(modify => $idx, $data);
Future->wrap
}
sub delete {
my ($self, $idx) = @_;
$self->splice($idx, 1, [])
}
# Locate matching element (via eq), starting at the given index
# and iterating either side until we hit it. For cases where splice
# activity may have moved the element but we're not expecting it to
# have gone far.
sub find_from {
my ($self, $idx, $data) = @_;
my $delta = 0;
my $end = $#{$self->{data}};
$idx = $end if $idx > $end;
$idx = 0 if $idx < 0;
ITEM:
lib/Adapter/Async/OrderedList/Array.pm view on Meta::CPAN
}
Future->wrap(\@items)
}
=head2 range
Retrieves all items in a range.
=over 4
=item * start
=item * end
=item * count
=item * on_item
=back
=cut
sub range {
my ($self, %args) = @_;
my $idx = delete $args{start} || 0;
my $code = delete $args{on_item};
my $max = $#{$self->{data}};
$args{end} //= $idx + $args{count} if exists $args{count};
$args{end} //= $max;
while($idx < $args{end}) {
last if $idx > $max;
$code->($idx, $self->{data}[$idx]);
++$idx;
}
Future->done
lib/Adapter/Async/OrderedList/Array.pm view on Meta::CPAN
sub find_insert_pos {
my ($self, $item, $code) = @_;
require List::BinarySearch;
$code ||= sub { ($a // '') cmp ($b // '') };
my $idx = List::BinarySearch::binsearch_pos($code, $item, $self->{data});
return defined($idx) ? Future->done($idx) : Future->fail('not found');
}
sub extract_first_by {
my ($self, $code, $start_idx) = @_;
$start_idx //= 0;
for my $idx ($start_idx..$#{$self->{data}}) {
if(grep $code->($_), $self->{data}[$idx]) {
return Future->done(CORE::splice @{$self->{data}}, $idx, 1);
}
}
return Future->done;
}
1;
__END__
lib/Adapter/Async/OrderedList/Array.pod view on Meta::CPAN
=head1 count
=head1 get
=head2 range
Retrieves all items in a range.
=over 4
=item * start
=item * end
=item * count
=item * on_item
=back
=head1 INHERITED METHODS
lib/Adapter/Async/UnorderedMap.pm view on Meta::CPAN
=item * splice - changes to the array which remove or add elements
=item * move - an existing element moves to a new key (some adapters may not be able to differentiate between this and splice: if in doubt, use splice instead, don't report as a move unless it's guaranteed to be existing items)
=back
The view raises these:
=over 4
=item * visible - indicates visibility of one or more items. change events will start being sent for these items.
visible => [1,2,3,4,5,6]
Filters may result in a list with gaps:
visible => [1,3,4,8,9,10]
Note that "visible" means "the user is able to see this data", so they'd be a single page of data rather than the entire set when no filters are applied. Visibility changes often - scrolling will trigger a visible/hidden pair for example.
Also note that ->get may be called on any element, regardless of visibility - prefetching is one common example here.
lib/Adapter/Async/UnorderedMap.pod view on Meta::CPAN
=item * splice - changes to the array which remove or add elements
=item * move - an existing element moves to a new key (some adapters may not be able to differentiate between this and splice: if in doubt, use splice instead, don't report as a move unless it's guaranteed to be existing items)
=back
The view raises these:
=over 4
=item * visible - indicates visibility of one or more items. change events will start being sent for these items.
visible => [1,2,3,4,5,6]
Filters may result in a list with gaps:
visible => [1,3,4,8,9,10]
Note that "visible" means "the user is able to see this data", so they'd be a single page of data rather than the entire set when no filters are applied. Visibility changes often - scrolling will trigger a visible/hidden pair for example.
Also note that ->get may be called on any element, regardless of visibility - prefetching is one common example here.
use warnings;
use Test::More;
use Test::Fatal;
use Future::Utils qw(fmap0);
use Adapter::Async::OrderedList::Array;
my $array = new_ok('Adapter::Async::OrderedList::Array');
is($array->count->get, 0, 'starts empty');
# Test an insert
$array->bus->subscribe_to_event(
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;
}
use strict;
use warnings;
use Test::More;
use Test::Fatal;
use Adapter::Async::UnorderedMap::Hash;
my $hash = new_ok('Adapter::Async::UnorderedMap::Hash');
is($hash->count->get, 0, 'starts empty');
ok(!$hash->exists(xyz =>)->get, 'key does not yet exist');
ok($hash->set_key(xyz => 1234)->get, 'can set a key');
ok($hash->exists(xyz =>)->get, 'key now exists');
is($hash->get_key(xyz =>)->get, '1234', 'read back key');
ok($hash->delete(xyz =>)->get, 'can delete a key');
ok(!$hash->exists(xyz =>)->get, 'key does not exist any more');
done_testing;