Adapter-Async

 view release on metacpan or  search on metacpan

lib/Adapter/Async/Model.pm  view on Meta::CPAN

	for my $k (keys %$def) {
		my $details = $def->{$k};
		$details = { type => $details } unless ref $details;
		my $code;
		my %collection_class_for = (
			UnorderedMap => 'Adapter::Async::UnorderedMap::Hash',
			OrderedList  => 'Adapter::Async::OrderedList::Array',
		);
		if(defined(my $from = $details->{from})) {
			$log->tracef("Should apply field %s from %s for %s", $k, $from, $pkg);
			++$loader{$_} for grep /::/, map $type_expand->($_), @{$details}{qw(type)};
		} else {
			no strict 'refs';
			no warnings 'once';
			push @{$pkg . '::attrs'}, $k unless $details->{collection}
		}

		if(my $type = $details->{collection}) {
			my $collection_class = $collection_class_for{$type} // die "unknown collection $type";
			++$loader{$collection_class};
			$log->tracef("%s->%s collection: %s", $pkg, $k, $type);
			++$loader{$_} for grep /::/, map $type_expand->($_), @{$details}{qw(key item)};
			$code = sub {
				my $self = shift;
				die "no args expected" if @_;
				$self->{$k} //= $collection_class->new;
			}
		} else {
			my $type = $type_expand->($details->{type} // die "unknown type in package $pkg - " . Dumper($def));
			++$loader{$type} if $type =~ /::/;

			$log->tracef("%s->%s scalar %s", $pkg, $k, $type);

lib/Adapter/Async/UnorderedMap.pm  view on Meta::CPAN

package Adapter::Async::UnorderedMap;
$Adapter::Async::UnorderedMap::VERSION = '0.019';
use strict;
use warnings;

use parent qw(Adapter::Async);

=head1 NAME

Adapter::Async::UnorderedMap - API for dealing with key => value maps

=head1 VERSION

version 0.018

=head1 DESCRIPTION

=head2 Accessing data

=over 4

lib/Adapter/Async/UnorderedMap.pod  view on Meta::CPAN

this file, but rather the original, inline with Adapter::Async::UnorderedMap
at lib/Adapter/Async/UnorderedMap.pm
(on the system that originally ran this).
If you do edit this file, and don't want your changes to be removed, make
sure you change the first line.

=cut

=head1 NAME

Adapter::Async::UnorderedMap - API for dealing with key => value maps

=head1 VERSION

version 0.018

=head1 DESCRIPTION

=head2 Accessing data

=over 4

t/00-compile.t  view on Meta::CPAN

use IO::Handle;

open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!";

my @warnings;
for my $lib (@module_files)
{
    # see L<perlfaq8/How can I capture STDERR from an external command?>
    my $stderr = IO::Handle->new;

    diag('Running: ', join(', ', map { my $str = $_; $str =~ s/'/\\'/g; q{'} . $str . q{'} }
            $^X, @switches, '-e', "require q[$lib]"))
        if $ENV{PERL_COMPILE_TEST_DEBUG};

    my $pid = open3($stdin, '>&STDERR', $stderr, $^X, @switches, '-e', "require q[$lib]");
    binmode $stderr, ':crlf' if $^O eq 'MSWin32';
    my @_warnings = <$stderr>;
    waitpid($pid, 0);
    is($?, 0, "$lib loaded ok");

    shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/

t/00-report-prereqs.t  view on Meta::CPAN


                if ( $DO_VERIFY_PREREQS && $type eq 'requires' ) {
                    push @dep_errors, "$mod is not installed ($req_string)";
                }
            }
        }

        if ( @reports ) {
            push @full_reports, "=== $title ===\n\n";

            my $ml = _max( map { length $_->[0] } @reports );
            my $wl = _max( map { length $_->[1] } @reports );
            my $hl = _max( map { length $_->[2] } @reports );

            if ($type eq 'modules') {
                splice @reports, 1, 0, ["-" x $ml, "", "-" x $hl];
                push @full_reports, map { sprintf("    %*s %*s\n", -$ml, $_->[0], $hl, $_->[2]) } @reports;
            }
            else {
                splice @reports, 1, 0, ["-" x $ml, "-" x $wl, "-" x $hl];
                push @full_reports, map { sprintf("    %*s %*s %*s\n", -$ml, $_->[0], $wl, $_->[1], $hl, $_->[2]) } @reports;
            }

            push @full_reports, "\n";
        }
    }
}

if ( @full_reports ) {
    diag "\nVersions for all modules listed in $source (including optional ones):\n\n", @full_reports;
}

t/array.t  view on Meta::CPAN

use strict;
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) = @_;

t/array.t  view on Meta::CPAN

	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(

t/model.t  view on Meta::CPAN

	package Local::Model::MapCollection;
	use Adapter::Async::Model {
		item => {
			collection => 'UnorderedMap',
			type => '::Item',
			key => 'int',
		}
	}, defer_methods => 0;
}
can_ok('Local::Model::MapCollection', qw(new item));
my $map = new_ok('Local::Model::MapCollection' => [
]);
is($map->item->count->get, 0, 'no item yet');
$map->item->set_key($item->id => $item)->get;
is($map->item->get_key($item->id)->get, $item, 'now have an item');

done_testing;




( run in 0.516 second using v1.01-cache-2.11-cpan-65fba6d93b7 )