App-Photobear
view release on metacpan or search on metacpan
252627282930313233343536373839404142434445
# Send the initial GET request
my
$response
=
$ua
->get(
$url
);
# Follow redirects if any
while
(
$response
->is_redirect) {
my
$redirect_url
=
$response
->header(
'Location'
);
$response
=
$ua
->get(
$redirect_url
);
}
say
STDERR
"[DEBUG] LWP::UserAgent Response code: "
,
$response
->code
if
$verbose
;
return
$response
->decoded_content;
};
if
($@) {
# Fallback to system curl command
eval
{
$output
= `curl --silent -L
$url
`;
say
STDERR
"[DEBUG] used curl: "
,
$output
if
$verbose
;
return
$output
;
};
if
($@) {
lib/App/Photobear.pm view on Meta::CPAN
125126127128129130131132133134135136137138139140141142143144145
# Send the initial GET request
my
$response
=
$ua
->get(
$url
);
# Follow redirects if any
while
(
$response
->is_redirect) {
my
$redirect_url
=
$response
->header(
'Location'
);
$response
=
$ua
->get(
$redirect_url
);
}
return
$response
->decoded_content;
};
if
($@) {
# Fallback to system curl command
eval
{
my
$output
= `curl --silent -L
$url
`;
return
$output
;
};
if
($@) {
die
"Can't get content of $url: $@"
;
lib/App/Photobear.pm view on Meta::CPAN
175176177178179180181182183184185186187188189190191192193194195196
my
$output
=
$ENV
{
'DEBUG'
} ?
$TEST_ANSWER
: `
$cmd
`;
if
($? == -1) {
Carp::croak(
"[photobear]"
,
"Failed to execute: $!\n"
);
}
elsif
($? & 127) {
Carp::croak(
"[photobear]"
,
sprintf
(
"Child died with signal %d, %s coredump\n"
),
($? & 127), ($? & 128) ?
'with'
:
'without'
);
}
elsif
($? >> 8) {
Carp::croak(
"[photobear]"
,
sprintf
(
"Child exited with value %d\n"
, $? >> 8));
}
my
$decoded_content
= decode_json(
$output
);
return
$decoded_content
;
}
sub
download {
my
(
$url
,
$dest
) =
@_
;
# Use curl
my
$cmd
=
qq(curl -L -o "$dest" "$url")
;
#
if
(
$TESTMODE
) {
return
1;
( run in 0.370 second using v1.01-cache-2.11-cpan-00829025b61 )