File Coverage

lib/PAGI/Utils.pm
Criterion Covered Total %
statement 25 25 100.0
branch 4 4 100.0
condition 3 5 60.0
subroutine 7 7 100.0
pod 1 1 100.0
total 40 42 95.2


line stmt bran cond sub pod time code
1             package PAGI::Utils;
2              
3 1     1   216389 use strict;
  1         2  
  1         40  
4 1     1   4 use warnings;
  1         6  
  1         59  
5 1     1   5 use Exporter 'import';
  1         1  
  1         35  
6 1     1   5 use Future::AsyncAwait;
  1         2  
  1         6  
7 1     1   51 use Carp qw(croak);
  1         1  
  1         58  
8 1     1   420 use PAGI::Lifespan;
  1         2  
  1         311  
9              
10             our @EXPORT_OK = qw(handle_lifespan);
11             our %EXPORT_TAGS = (all => \@EXPORT_OK);
12              
13 6     6 1 249781 async sub handle_lifespan {
14 6         23 my ($scope, $receive, $send, %opts) = @_;
15              
16 6   50     25 my $type = $scope->{type} // '';
17 6 100       257 croak "handle_lifespan called with scope type '$type' (expected 'lifespan'). "
18             . "Check scope type before calling: "
19             . "return await handle_lifespan(...) if \$scope->{type} eq 'lifespan'"
20             unless $type eq 'lifespan';
21              
22 5         31 my $manager = PAGI::Lifespan->for_scope($scope);
23 5 100 66     40 $manager->register(%opts) if $opts{startup} || $opts{shutdown};
24              
25 5         22 return await $manager->handle($scope, $receive, $send);
26             }
27              
28             1;
29              
30             __END__