Skip to content

Commit

Permalink
Packaging it up for CPAN
Browse files Browse the repository at this point in the history
  • Loading branch information
davorg committed Dec 2, 2018
1 parent 6526e3f commit 8492d3e
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 7 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
*.svg
MANIFEST.bak
MYMETA.json
MYMETA.yml
Makefile
SVG-ChristmasTree-*.tar.gz
blib/
pm_to_blib

8 changes: 8 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Change Log

## [0.0.1] - 2018-12-02

### Added

- All the things. Merry Christmas!

9 changes: 9 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
bin/tree
Changes.md
lib/SVG/ChristmasTree.pm
Makefile.PL
MANIFEST
MANIFEST.SKIP
MYMETA.json
MYMETA.yml
t/basic.t
7 changes: 7 additions & 0 deletions MANIFEST.SKIP
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.*\.svg
blib/*
SVG-ChristmasTree-*
.git/
.gitignore
.*\.bak
Makefile$
36 changes: 36 additions & 0 deletions Makefile.PL
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use ExtUtils::MakeMaker;

WriteMakefile(
NAME => 'SVG::ChristmasTree',
VERSION_FROM => 'lib/SVG/ChristmasTree.pm',
LICENSE => 'perl_5',
MIN_PERL_VERSION => '5.10.0',

BUILD_REQUIRES => {
'Test::More' => 0,
'ExtUtils::MakeMaker' => 0,
SVG => 0,
Moose => 0,
POSIX => 0,
'Math::Trig' => 0,
'namespace::autoclean' => 0,
},
PREREQ_PM => {
SVG => 0,
Moose => 0,
POSIX => 0,
'Math::Trig' => 0,
'namespace::autoclean' => 0,
},
META_MERGE => {
'meta-spec' => { version => 2 },
resources => {
repository => {
type => 'git',
url => 'git://github.com/davorg/svg-christmastree.git',
web => 'https://github.com/davorg/svg-christmastree',
},
},
},
EXE_FILES => [ 'bin/tree' ],
);
20 changes: 20 additions & 0 deletions bin/tree
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,23 @@ use SVG::ChristmasTree;
my $tree = SVG::ChristmasTree->new_with_options;

say $tree->as_xml;

=head1 NAME
tree
=head1 DESCRIPTION
Draw an SVG Christmas tree.
=head1 SYNOPSIS
Draw the default Christmas tree.
$ ./tree > my_tree.svg
Draw a different Christmas tree.
$ ./tree --layers=5 --pot_colour='rgb(0,0,255)' > another_tree.svg
=head1 OPTIONS
23 changes: 19 additions & 4 deletions lib/SVG/ChristmasTree.pm
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ use POSIX 'round';

with 'MooseX::Getopt';

our $VERSION = '0.0.1';

# Constants that we haven't made into attributes yet
use constant {
TREE_WIDTH => 600, # Width of the bottom tree layer
Expand Down Expand Up @@ -255,10 +257,10 @@ sub as_xml {
$self->trunk;

for (@{$self->triangles}) {
my $h = $self->triangle(TOP_ANGLE, $_->{w}, $_->{b});
my $h = $self->_triangle(TOP_ANGLE, $_->{w}, $_->{b});
$self->bauble($self->_mid_y - ($_->{w}/2), $_->{b});
$self->bauble($self->_mid_y + ($_->{w}/2), $_->{b});
$self->coloured_shape(
$self->_coloured_shape(
$_->{x}, $_->{y}, $self->leaf_colour,
);
}
Expand All @@ -271,7 +273,7 @@ sub pot {

my $pot_top = $self->height - $self->pot_height;

$self->coloured_shape(
$self->_coloured_shape(
[ $self->_mid_y - (POT_BOT_WIDTH / 2),
$self->_mid_y - (POT_TOP_WIDTH / 2),
$self->_mid_y + (POT_TOP_WIDTH / 2),
Expand All @@ -287,7 +289,7 @@ sub trunk {
my $trunk_bottom = $self->height - $self->pot_height;
my $trunk_top = $trunk_bottom - $self->trunk_length;

$self->coloured_shape(
$self->_coloured_shape(
[ $self->_mid_y - (TRUNK_WIDTH / 2), $self->_mid_y - (TRUNK_WIDTH / 2),
$self->_mid_y + (TRUNK_WIDTH / 2), $self->_mid_y + (TRUNK_WIDTH / 2) ],
[ $trunk_bottom, $trunk_top, $trunk_top, $trunk_bottom ],
Expand Down Expand Up @@ -359,4 +361,17 @@ sub _coloured_shape {
);
}

=head1 AUTHOR
Dave Cross <dave@perlhacks.com>
=head1 COPYRIGHT AND LICENCE
Copyright (c) 2018, Magnum Solutions Ltd. All Rights Reserved.
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=cut

1;
5 changes: 2 additions & 3 deletions t/basic.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ use SVG::ChristmasTree;
ok(my $tree = SVG::ChristmasTree->new, 'Got an object');
isa_ok($tree, 'SVG::ChristmasTree');
is($tree->width, 1_000, 'Width is correct');
is($tree->height, 1_000, 'Height is correct');
is($tree->height, 873, 'Height is calculated correctly');
isa_ok($tree->svg, 'SVG', 'SVG attribute');
can_ok($tree, 'as_xml');

$tree->pot;
ok(my $xml = $tree->as_xml, 'Got some XML');

done_testing;

0 comments on commit 8492d3e

Please sign in to comment.