Badge-Depot
view release on metacpan or search on metacpan
lib/Badge/Depot.pm view on Meta::CPAN
use strict;
use warnings;
package Badge::Depot;
# ABSTRACT: A framework for badges
our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY
our $VERSION = '0.0104';
use Moose::Role;
use Types::URI qw/Uri/;
use Types::Standard qw/Str InstanceOf/;
use MooseX::AttributeShortcuts;
use namespace::autoclean;
has image_url => (
is => 'rw',
isa => Uri,
init_arg => undef,
coerce => 1,
predicate => 1,
);
has image_alt => (
is => 'rw',
isa => Str,
init_arg => undef,
predicate => 1,
);
has link_url => (
is => 'rw',
isa => Uri,
init_arg => undef,
coerce => 1,
predicate => 1,
);
has zilla => (
is => 'ro',
isa => InstanceOf['Dist::Zilla'],
predicate => 1,
);
around qw/to_html to_markdown/ => sub {
my $next = shift;
my $self = shift;
return '' if !$self->has_image_url;
$self->$next;
};
sub to_html {
my $self = shift;
my $image_text = $self->has_image_alt ? sprintf ' alt="%s"', $self->image_alt : '';
if($self->has_link_url) {
return sprintf q{<a href="%s"><img src="%s"%s /></a>}, $self->link_url, $self->image_url, $image_text;
}
else {
return sprintf q{<img src="%s"%s />}, $self->image_url, $image_text;
}
}
sub to_markdown {
my $self = shift;
if($self->has_link_url) {
return sprintf q<[](%s)>, $self->image_alt // '', $self->image_url, $self->link_url;
}
else {
return sprintf q<>, $self->image_alt // '', $self->image_url;
}
}
1;
( run in 1.219 second using v1.01-cache-2.11-cpan-9581c071862 )