blib/lib/Badge/Depot.pm

filter: Statementstmt 100% 40 / 40 Branchbran 100% 8 / 8 Conditioncond 100% 4 / 4 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 100% 66 / 66 SCAR 19.5
CC
7
Cov
100%
to_markdown
4.0
to_html
3.0
__ANON__
2.0
CRAP 7.0
↑ Summary Build »
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  
4 package Badge::Depot;
5  
6 1 our $VERSION = '0.0103'; # VERSION
7 # ABSTRACT: A framework for badges
8  
9 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Types::URI qw/Uri/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Types::Standard qw/Str/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use MooseX::AttributeShortcuts;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 has image_url => (
16 is => 'rw',
17 isa => Uri,
18 init_arg => undef,
19 coerce => 1,
20 predicate => 1,
21 );
22 1 has image_alt => (
23 is => 'rw',
24 isa => Str,
25 init_arg => undef,
26 predicate => 1,
27 );
28 1 has link_url => (
29 is => 'rw',
30 isa => Uri,
31 init_arg => undef,
32 coerce => 1,
33 predicate => 1,
34 );
35  
36 around qw/to_html to_markdown/ => sub {
37 10 ▶ my $next = shift;
Subroutine __ANON__: called CC=2 SCAR=6.9
38 10 my $self = shift;
39  
40 10 ▶ return '' if !$self->has_image_url;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_image_url 2 8 10
41 8 $self->$next;
42 1 };
43  
44 sub to_html {
45 4 ▶ my $self = shift;
Subroutine to_html: called CC=3 SCAR=11.0
Pod documented
46  
47 4 ▶ my $image_text = $self->has_image_alt ? sprintf ' alt="%s"', $self->image_alt : '';
Branch: 1 branch
BranchTrueFalseTotal
$self->has_image_alt ? : 2 2 4
48  
49 4 ▶ if($self->has_link_url) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_link_url) { } 2 2 4
50 2 return sprintf q{<a href="%s"><img src="%s"%s /></a>}, $self->link_url, $self->image_url, $image_text;
51 }
52 else {
53 2 return sprintf q{<img src="%s"%s />}, $self->image_url, $image_text;
54 }
55 }
56 sub to_markdown {
57 4 ▶ my $self = shift;
Subroutine to_markdown: called CC=4 SCAR=13.9
Pod documented
58  
59 4 ▶ if($self->has_link_url) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_link_url) { } 2 2 4
60 2 ▶ return sprintf q<[![%s](%s)](%s)>, $self->image_alt // '', $self->image_url, $self->link_url;
Condition100%2/2
$self->image_alt // ""
l!l
11
MC/DC100%1/1
$self->image_alt // ""
$self->image_alt
Truth table100%2/2
A
A= $self->image_alt
Aresult
11
00
61 }
62 else {
63 2 ▶ return sprintf q<![%s](%s)>, $self->image_alt // '', $self->image_url;
Condition100%2/2
$self->image_alt // ""
l!l
11
MC/DC100%1/1
$self->image_alt // ""
$self->image_alt
Truth table100%2/2
A
A= $self->image_alt
Aresult
11
00
64 }
65 }
66  
67 1 1;
68  
69 __END__
70  
71 =pod
72  
73 =encoding UTF-8
74  
75 =head1 NAME
76  
77 Badge::Depot - A framework for badges
78  
79 =head1 VERSION
80  
81 Version 0.0103, released 2015-03-19.
82  
83 =head1 SYNOPSIS
84  
85 # Define a badge class
86 package Badge::Depot::Plugin::Example;
87  
88 use Moose;
89 with 'Badge::Depot';
90  
91 has user => (
92 is => 'ro',
93 isa => 'Str',
94 required => 1,
95 );
96  
97 sub BUILD {
98 my $self = shift;
99 $self->link_url(sprintf 'https://example.com/users/%s', $self->user);
100 $self->image_url(sprintf 'https://example.com/users/%s.svg', $self->user);
101 $self->image_alt('Example text');
102 }
103  
104 # Somewhere else
105 my $badge = Badge::Depot::Plugin::Example->new(user => 'my_username');
106  
107 print $badge->to_html;
108 # prints '<a href="https://example.com/users/my_username"><img src="https://example.com/users/my_username.svg" alt="Example text" /></a>'
109  
110 =head1 DESCRIPTION
111  
112 C<Badge::Depot> is a framework for documentation badges. Using badges in your documentation can give
113 end users of your distribution dynamic information without you having to update the documentation.
114  
115 You only need use this distribution directly if you want to create a new badge in the C<Badge::Depot::Plugin> namespace. See L<Task::Badge::Depot> for
116 a list of existing badges.
117  
118 For use together with L<Pod::Weaver>, see L<Pod::Weaver::Section::Badges>.
119  
120 =head1 OVERVIEW
121  
122 C<Badge::Depot> is a L<Moose> role that adds a few attributes and methods.
123  
124 =head1 ATTRIBUTES
125  
126 These attributes are expected to be set when the badge class returns from C<new>. See L<synopsis|/SYNOPSIS>.
127  
128 =head2 image_url
129  
130 Required. L<Uri|Types::URI>.
131  
132 The url to the actual badge. The src attribute for the img tag when rendered to html.
133  
134 =head2 image_alt
135  
136 Optional. L<Str|Types::Standard>.
137  
138 The alternative text of the badge. The alt attribute for the img tag when rendered to html. No alternative text is created if this isn't set.
139  
140 =head2 link_url
141  
142 Optional (but recommended). L<Uri|Types::URI>.
143  
144 The url to link the badge to. The href attribute for the a tag when rendered to html. No link is created if this isn't set.
145  
146 =head1 METHODS
147  
148 These methods are used when rendering the badge, and are not useful inside badge classes.
149  
150 =head2 to_html
151  
152 Returns a string with the badge rendered as html.
153  
154 =head2 to_markdown
155  
156 Returns a string with the badge rendered as markdown.
157  
158 =head1 SEE ALSO
159  
160 =over 4
161  
162 =item *
163  
164 L<Task::Badge::Depot> - List of available badges
165  
166 =item *
167  
168 L<Pod::Weaver::Section::Badges> - Weave the badges
169  
170 =item *
171  
172 L<WWW::StatusBadge> - An alternative badge framework
173  
174 =back
175  
176 =head1 SOURCE
177  
178 L<https://github.com/Csson/p5-Badge-Depot>
179  
180 =head1 HOMEPAGE
181  
182 L<https://metacpan.org/release/Badge-Depot>
183  
184 =head1 AUTHOR
185  
186 Erik Carlsson <info@code301.com>
187  
188 =head1 COPYRIGHT AND LICENSE
189  
190 This software is copyright (c) 2015 by Erik Carlsson <info@code301.com>.
191  
192 This is free software; you can redistribute it and/or modify it under
193 the same terms as the Perl 5 programming language system itself.
194  
195 =cut
↑ Summary Build »