Adapter-Async
view release on metacpan or search on metacpan
lib/Adapter/Async/OrderedList.pm view on Meta::CPAN
Some views won't raise this - if touch control is involved, for example
=item * activate - some action has been performed.
activate => [1]
activate => [1,2,5,6,7,8]
Multi-activate will typically happen when items have been selected rather than just highlighted.
The adapter itself doesn't do much with this.
=back
=cut
=head1 METHODS
=head2 insert
Inserts data before the given position.
$adapter->insert(3, [...])
=cut
sub insert {
my ($self, $idx, $data) = @_;
$self->splice($idx, 0, $data)
}
=head2 append
Appends data after the given position.
$adapter->append(3, [...])
=cut
sub append {
my ($self, $idx, $data) = @_;
$self->splice($idx + 1, 0, $data)
}
=head2 push
Appends data to the end of the list.
=cut
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 {
my ($self, $data) = @_;
$self->splice(0, 0, $data)
}
=head2 pop
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 {
my ($self, $data) = @_;
$self->splice(0, 1)
}
=head2 all
Returns all the items. Shortcut for calling
L</count> then L</get>.
=cut
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>
=head1 LICENSE
Copyright Tom Molesworth 2013-2015. Licensed under the same terms as Perl itself.
( run in 1.845 second using v1.01-cache-2.11-cpan-d80b1682f3f )