Cloudinary
view release on metacpan or search on metacpan
lib/Mojolicious/Plugin/Cloudinary.pm view on Meta::CPAN
package Mojolicious::Plugin::Cloudinary;
use Mojo::Base -base;
use File::Basename;
use Mojo::UserAgent;
use Mojo::Util qw(sha1_sum url_escape);
use Scalar::Util 'weaken';
use base qw(Cloudinary Mojolicious::Plugin);
our $VERSION = 0.0402; # just need something higher than the previous version
has js_image => '/image/blank.png';
sub register {
my ($self, $app, $config) = @_;
for my $k (keys %{$config || {}}) {
$self->$k($config->{$k}) if exists $config->{$k};
}
$self->_ua($app->ua);
$app->helper(
cloudinary_upload => sub {
my $c = shift;
$self->upload(@_);
}
);
$app->helper(
cloudinary_destroy => sub {
my $c = shift;
$self->destroy(@_);
}
);
$app->helper(
cloudinary_url_for => sub {
my ($c, $public_id, $args) = @_;
my $scheme = $c->req->url->scheme || '';
if (not defined $args->{secure} and $scheme eq 'https') {
$args->{secure} = 1;
}
return $self->url_for($public_id, $args);
}
);
$app->helper(
cloudinary_image => sub {
my ($c, $public_id, $args, $image_args) = @_;
my $scheme = $c->req->url->scheme || '';
if (not defined $args->{secure} and $scheme eq 'https') {
$args->{secure} = 1;
}
return $c->image($self->url_for($public_id, $args), alt => $public_id, %$image_args);
}
);
$app->helper(
cloudinary_js_image => sub {
my ($c, $public_id, $args) = @_;
my $scheme = $c->req->url->scheme || '';
if (not defined $args->{secure} and $scheme eq 'https') {
$args->{secure} = 1;
}
( run in 2.392 seconds using v1.01-cache-2.11-cpan-0bb4e1dffa6 )