04 Nov 2018 19:27:56 UTC
- Distribution: Badge-Simple
- Module version: 0.04
- Source (raw)
- Browse (raw)
- How to Contribute
- Testers (627 / 0 / 0)
- KwaliteeBus factor: 1
- % Coverage
- License: perl_5
- Perl: v5.6.0
- Activity24 month
- Download (391.33KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest version
Badge::Simple - Generate simple SVG badges
use Badge::Simple qw/badge/; badge( left => "Hello", right => "World!", color => "yellow" ) ->toFile( "hello.svg" );→
This module generates simple badges, based heavily on the default "flat" style of Shields.io.
The module currently exports a single function,
badge, which returns an XML::LibXML::Document object representing the SVG file. The function takes the following arguments:
Text on the left side of the badge. Required.
Text on the right side of the badge. Required.
Either an HTML hex color string (
"#AABBCC"), or one of the following predefined color schemes:
yellowgreen. If omitted, defaults to
The filename of a font file (as supported by Imager::Font), for example you might point this at your local copy of Verdana.ttf. This font is currently only used to calculate the width of the badge. If omitted, defaults to DejaVuSans.ttf, which is distributed with this module.
Note: Different font libraries may calculate the widths of fonts slightly differently. This module's tests check to make sure that these variations are not too large (within a couple of pixels), but be aware that badges generated on different systems might have slightly different widths.
The return value of
badge, an XML::LibXML::Document object, can easily be used in one of the following ways (
$svgis the return value):
Write to a file:
Save to a string:
my $string = $svg->toString();
Write to a file with the XML nicely indented:
Save to a string with the XML nicely indented:
my $string = $svg->toString(1);
The following samples should be visible if you are viewing an HTML version of this documentation and you have an Internet connection available. Otherwise, please see the sample images in the t/ directory of the module distribution.
badge( left => "Hello", right => "World!", color => "yellow" )→
badge( left=>'CPAN Testers', right=>'100%', color=>'brightgreen' )→
badge( left=>'foo', right=>'bar', color=>'#e542f4' )→
Copyright (c) 2018 Hauke Daempfling (email@example.com).
This library is free software; you can redistribute it and/or modify it under the same terms as Perl 5 itself.
Please see the file README.md in the module's distribution for additional information.
Module Install Instructions
To install Badge::Simple, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell install Badge::Simple
For more information on module installation, please visit the detailed CPAN module installation guide.