Zing/Poll.pm

filter: Statementstmt 71.0% 27 / 38 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 88.8% 8 / 9 Podpod 100% 1 / 1 totaltotal 66.6% 36 / 54 CC 4 SCAR 19.9
CC
4
Cov
61%
await
20.0
BEGIN
1.0
BEGIN
1.0
CRAP 7.3
« Zing/Logic.pm ↑ Summary Zing/Store.pm »
1 package Zing::Poll;
2  
3 56 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 56 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 56 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 56 ▶use registry 'Zing::Types';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 56 ▶use routines;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 56 ▶use Data::Object::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 56 ▶use Data::Object::ClassHas;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 56 ▶use Time::HiRes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 56 our $VERSION = '0.26'; # VERSION
17  
18 # ATTRIBUTES
19  
20 56 has 'repo' => (
21 is => 'ro',
22 isa => 'Repo',
23 req => 1,
24 );
25  
26 # METHODS
27  
28 0 ▶method await(Int $secs) {
Subroutine await: not called CC=4 SCAR=30.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
Type::Tiny::XS::Int($secs) or Function::Parameters::_croak('In method await: parameter 1 ($secs): ' . ${my $v = bless( {"_is_core" => 1,"_overload_coderef" => sub { package Sub::Defer; use warnings; use strict; $undeferred ||= undefer_sub($deferred_info->[4]); goto \&$undeferred;},"_overload_coderef_no_rebuild" => 1,"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Int","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"constraint" => sub { package Types::Standard; no warnings; use strict; /\A-?[0-9]+\z/;},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 361,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Int","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; use warnings; use strict; $Type::Tiny::AvoidCallbacks ? goto $orig_inlined : "$xsubname($_[1])";},"library" => "Types::Standard","name" => "Int","parent" => bless( {"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; defined $_[0] and not ref $_[0] and &Scalar::Util::looks_like_number($_[0]) or _failed_check(12, 'Num', $_[0], 'exception_class', 'Error::TypeTiny::Assertion'); $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ($) { package Eval::TypeTiny::Sandbox; use strict; defined $_[0] and not ref $_[0] and &Scalar::Util::looks_like_number($_[0]);},"display_name" => "to_Num","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"constraint" => sub { package Type::Tiny; use warnings; use strict; !0;},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 344,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Num","exception_class" => "Error::TypeTiny::Assertion","library" => "Types::Standard","name" => "Num","parent" => bless( {"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; defined $_[0] and not ref $_[0] and &Scalar::Util::looks_like_number($_[0]) or _failed_check(10, 'LaxNum', $_[0], 'exception_class', 'Error::TypeTiny::Assertion'); $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => do{my $o},"display_name" => "to_LaxNum","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"constraint" => sub { package Types::Standard; no warnings; use strict; looks_like_number $_ and ref \$_ ne 'GLOB';},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 309,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "LaxNum","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; &$maybe_load_modules('Scalar::Util', 'Scalar::Util'->VERSION ge '1.18' ? "defined($_[1]) && !ref($_[1]) && Scalar::Util::looks_like_number($_[1])" : "defined($_[1]) && !ref($_[1]) && Scalar::Util::looks_like_number($_[1]) && ref(\\($_[1])) ne 'GLOB'");},"library" => "Types::Standard","name" => "LaxNum","parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Sub::Defer; use warnings; use strict; $undeferred ||= undefer_sub($deferred_info->[4]); goto \&$undeferred;},"_overload_coderef_no_rebuild" => 1,"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Str","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"constraint" => sub { package Types::Standard; no warnings; use strict; ref \$_ eq 'SCALAR' or ref \(my $val = $_) eq 'SCALAR';},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 291,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Str","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; use warnings; use strict; $Type::Tiny::AvoidCallbacks ? goto $orig_inlined : "$xsubname($_[1])";},"library" => "Types::Standard","name" => "Str","parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; defined $_[0] and not ref $_[0] or _failed_check(8, 'Value', $_[0], 'exception_class', 'Error::TypeTiny::Assertion'); $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Value","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"constraint" => sub { package Types::Standard; no warnings; use strict; not ref $_;},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 276,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Value","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; "defined($_[1]) and not ref($_[1])";},"library" => "Types::Standard","name" => "Value","parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; defined $_[0] or _failed_check(7, 'Defined', $_[0], 'exception_class', 'Error::TypeTiny::Assertion'); $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Defined","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"complementary_type" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; defined $_[0] and _failed_check(6, 'Undef', $_[0], 'exception_class', 'Error::TypeTiny::Assertion'); $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Undef","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"complementary_type" => {},"constraint" => sub { package Types::Standard; no warnings; use strict; not defined $_;},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 254,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Undef","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; "!defined($_[1])";},"library" => "Types::Standard","name" => "Undef","parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; '???'; $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Item","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"constraint" => do{my $o},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 226,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Item","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; '!!1';},"library" => "Types::Standard","name" => "Item","parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; '???'; $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => do{my $o},"display_name" => "to_Any","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"complement_name" => "None","constraint" => do{my $o},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 220,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Any","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; '!!1';},"library" => "Types::Standard","name" => "Any","type_default" => sub { package Types::Standard; no warnings; use strict; return undef;},"uniq" => 1}, 'Type::Tiny' ),"uniq" => 2}, 'Type::Tiny' ),"type_default" => sub { package Types::Standard; no warnings; use strict; return undef;},"uniq" => 6}, 'Type::Tiny' ),"constraint" => sub { package Types::Standard; no warnings; use strict; defined $_;},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 262,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Defined","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; "defined($_[1])";},"library" => "Types::Standard","name" => "Defined","parent" => {},"uniq" => 7}, 'Type::Tiny' ),"uniq" => 8}, 'Type::Tiny' ),"sorter" => sub { package Types::Standard; no warnings; use strict; $_[0] cmp $_[1];},"type_default" => sub { package Types::Standard; no warnings; use strict; return '';},"uniq" => 9}, 'Type::Tiny' ),"sorter" => sub { package Types::Standard; no warnings; use strict; $_[0] <=> $_[1];},"type_default" => sub { package Types::Standard; no warnings; use strict; return 0;},"uniq" => 10}, 'Type::Tiny' ),"uniq" => 12}, 'Type::Tiny' ),"type_default" => sub { package Types::Standard; no warnings; use strict; return 0;},"uniq" => 13}, 'Type::Tiny' );$v->{"coercion"}{"type_constraint"} = $v;$v->{"compiled_type_constraint"} = $v->{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"};$v->{"parent"}{"compiled_type_constraint"} = $v->{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"} = $v->{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"}{"parent"};$v->{"parent"}{"parent"}{"compiled_type_constraint"} = $v->{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"}{"parent"}{"parent"};$v->{"parent"}{"parent"}{"parent"}{"compiled_type_constraint"} = $v->{"parent"}{"parent"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"parent"}{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"}{"parent"}{"parent"}{"parent"};$v->{"parent"}{"parent"}{"parent"}{"parent"}{"compiled_type_constraint"} = $v->{"parent"}{"parent"}{"parent"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"parent"}{"parent"}{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"}{"parent"}{"parent"}{"parent"}{"parent"};$v->{"parent"}{"parent"}{"parent"}{"parent"}{"parent"}{"compiled_type_constraint"} = $v->{"parent"}{"parent"}{"parent"}{"parent"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"parent"}{"parent"}{"parent"}{"complementary_type"}{"coercion"}{"type_constraint"} = $v->{"parent"}{"parent"}{"parent"}{"parent"}{"parent"}{"complementary_type"};$v->{"parent"}{"parent"}{"parent"}{"parent"}{"parent"}{"complementary_type"}{"compiled_type_constraint"} = $v->{"parent"}{"parent"}{"parent"}{"parent"}{"parent"}{"complementary_type"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"parent"}{"parent"}{"parent"}{"complementary_type"}{"complementary_type"} = $v->{"parent"}{"parent"}{"parent"}{"parent"}{"parent"};$v->{"parent"}{"parent"}{"parent"}{"parent"}{"parent"}{"complementary_type"}{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"}{"parent"}{"parent"}{"parent"}{"parent"}{"complementary_type"}{"parent"};$v->{"parent"}{"parent"}{"parent"}{"parent"}{"parent"}{"complementary_type"}{"parent"}{"compiled_type_constraint"} = $v->{"parent"}{"parent"}{"parent"}{"parent"}{"parent"}{"complementary_type"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"parent"}{"parent"}{"parent"}{"complementary_type"}{"parent"}{"constraint"} = $v->{"parent"}{"constraint"};$v->{"parent"}{"parent"}{"parent"}{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"} = $v->{"parent"}{"parent"}{"parent"}{"parent"}{"parent"}{"complementary_type"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"parent"}{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"}{"parent"}{"parent"}{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"};$v->{"parent"}{"parent"}{"parent"}{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"}{"compiled_type_constraint"} = $v->{"parent"}{"parent"}{"parent"}{"parent"}{"parent"}{"complementary_type"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"parent"}{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"}{"constraint"} = $v->{"parent"}{"constraint"};$v->{"parent"}{"parent"}{"parent"}{"parent"}{"parent"}{"parent"} = $v->{"parent"}{"parent"}{"parent"}{"parent"}{"parent"}{"complementary_type"}{"parent"}; \$v}->get_message($secs)) 0 0 0
29 0 my $data;
30 0 my $repo = $self->repo;
31 0 my @tres = (Time::HiRes::gettimeofday);
32 0 my $time = join('', $tres[0] + $secs, $tres[1]);
33  
34 0 ▶ until ($data = $repo->recv) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($data = $repo->recv) 0 0 0
35 0 ▶ last if join('', Time::HiRes::gettimeofday) >= $time;
Branch: 1 branch
BranchTrueFalseTotal
if join("", &Time::HiRes::gettimeofday()) >= $time 0 0 0
36 }
37  
38 0 return $data;
39 56 }
40  
41 56 1;
42  
43 =encoding utf8
44  
45 =head1 NAME
46  
47 Zing::Poll - Blocking Receive
48  
49 =cut
50  
51 =head1 ABSTRACT
52  
53 Blocking Receive Construct
54  
55 =cut
56  
57 =head1 SYNOPSIS
58  
59 use Zing::Poll;
60 use Zing::KeyVal;
61  
62 my $poll = Zing::Poll->new(repo => Zing::KeyVal->new(name => 'notes'));
63  
64 # $poll->await(0);
65  
66 =cut
67  
68 =head1 DESCRIPTION
69  
70 This package provides an algorithm for preforming a blocking receive by polling
71 the datastore for a specific item.
72  
73 =cut
74  
75 =head1 LIBRARIES
76  
77 This package uses type constraints from:
78  
79 L<Zing::Types>
80  
81 =cut
82  
83 =head1 ATTRIBUTES
84  
85 This package has the following attributes:
86  
87 =cut
88  
89 =head2 repo
90  
91 repo(Repo)
92  
93 This attribute is read-only, accepts C<(Repo)> values, and is required.
94  
95 =cut
96  
97 =head1 METHODS
98  
99 This package implements the following methods:
100  
101 =cut
102  
103 =head2 await
104  
105 await(Int $secs) : Maybe[HashRef]
106  
107 The await method polls the datastore specified for the data at the key
108 specified, for at-least the number of seconds specified, and returns the data
109 or undefined.
110  
111 =over 4
112  
113 =item await example #1
114  
115 # given: synopsis
116  
117 $poll->await(0);
118  
119 =back
120  
121 =over 4
122  
123 =item await example #2
124  
125 # given: synopsis
126  
127 $poll->repo->send({ task => 'write research paper' });
128  
129 $poll->await(0);
130  
131 =back
132  
133 =cut
134  
135 =head1 AUTHOR
136  
137 Al Newkirk, C<awncorp@cpan.org>
138  
139 =head1 LICENSE
140  
141 Copyright (C) 2011-2019, Al Newkirk, et al.
142  
143 This is free software; you can redistribute it and/or modify it under the terms
144 of the The Apache License, Version 2.0, as elucidated in the L<"license
145 file"|https://github.com/iamalnewkirk/zing/blob/master/LICENSE>.
146  
147 =head1 PROJECT
148  
149 L<Wiki|https://github.com/iamalnewkirk/zing/wiki>
150  
151 L<Project|https://github.com/iamalnewkirk/zing>
152  
153 L<Initiatives|https://github.com/iamalnewkirk/zing/projects>
154  
155 L<Milestones|https://github.com/iamalnewkirk/zing/milestones>
156  
157 L<Contributing|https://github.com/iamalnewkirk/zing/blob/master/CONTRIBUTE.md>
158  
159 L<Issues|https://github.com/iamalnewkirk/zing/issues>
160  
161 =cut
« Zing/Logic.pm ↑ Summary Zing/Store.pm »