| 1 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | package Juno::Check::HTTP; | ||||||||||
| 4 | # ABSTRACT: An HTTP check for Juno | ||||||||||
| 5 | 1 | $Juno::Check::HTTP::VERSION = '0.010'; | |||||||||
| 6 | 1 | ▶ | use AnyEvent::HTTP; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use MooX::Types::MooseLike::Base qw<Str HashRef>; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use namespace::sweep; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 1 | with 'Juno::Role::Check'; | |||||||||
| 12 | |||||||||||
| 13 | has path => ( | ||||||||||
| 14 | is => 'ro', | ||||||||||
| 15 | isa => Str, | ||||||||||
| 16 | 0 | ▶ | default => sub {'/'}, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 17 | 1 | ); | |||||||||
| 18 | |||||||||||
| 19 | has headers => ( | ||||||||||
| 20 | is => 'ro', | ||||||||||
| 21 | isa => HashRef, | ||||||||||
| 22 | 0 | ▶ | default => sub { {} }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 23 | 1 | ); | |||||||||
| 24 | |||||||||||
| 25 | 0 | ▶ | sub check { | ||||||||
|
Subroutine
check: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 26 | 0 | my $self = shift; | |||||||||
| 27 | 0 | my @hosts = @{ $self->hosts }; | |||||||||
| 28 | 0 | my $path = $self->path; | |||||||||
| 29 | |||||||||||
| 30 | 0 | foreach my $host (@hosts) { | |||||||||
| 31 | 0 | my $url = "http://$host" . $path; | |||||||||
| 32 | |||||||||||
| 33 | 0 | ▶ | $self->has_on_before | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | and $self->on_before->( $self, $host ); | ||||||||||
| 35 | |||||||||||
| 36 | 0 | ▶ | http_get $url, $self->headers, sub { | ||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||
| 37 | 0 | my ( $body, $headers ) = @_; | |||||||||
| 38 | |||||||||||
| 39 | 0 | ▶ | $self->has_on_result | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | and $self->on_result->( $self, $host, $body, $headers ); | ||||||||||
| 41 | |||||||||||
| 42 | 0 | ▶ | if ( $headers->{'Status'} =~ /^2/ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | 0 | ▶ | $self->has_on_success | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | and $self->on_success->( $self, $host, $body, $headers ); | ||||||||||
| 45 | } else { | ||||||||||
| 46 | 0 | ▶ | $self->has_on_fail | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | and $self->on_fail->( $self, $host, $body, $headers ); | ||||||||||
| 48 | } | ||||||||||
| 49 | 0 | }; | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 0 | return 0; | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 1 | 1; | |||||||||
| 56 | |||||||||||
| 57 | __END__ | ||||||||||