File: uri_status_code.pm

package info (click to toggle)
libcatmandu-identifier-perl 0.15-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 292 kB
  • sloc: perl: 978; makefile: 2
file content (43 lines) | stat: -rw-r--r-- 726 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package Catmandu::Fix::uri_status_code;

our $VERSION = '0.15';

use Catmandu::Sane;
use LWP::UserAgent;
use Moo;
use Catmandu::Fix::Has;

with 'Catmandu::Fix::Base';

has path => (fix_arg => 1);

sub emit {
    my ($self, $fixer) = @_;
    my $path = $fixer->split_path($self->path);

    $fixer->emit_create_path(
        $fixer->var,
        $path,
        sub {
            my $var = shift;
            "${var} = LWP::UserAgent->new->get(${var})->code if is_value(${var}) && length(${var});";
        }
    );
}

=head1 NAME

Catmandu::Fix::uri_status_code - check the HTTP status of a uri

=head1 SYNOPSIS

  copy_field(url,status)
  uri_status_code(status) # status => '200'

=head1 SEE ALSO

L<Catmandu::Fix>

=cut

1;