File Coverage

blib/lib/Shodo.pm
Criterion Covered Total %
statement 40 42 95.2
branch 8 10 80.0
condition n/a
subroutine 12 12 100.0
pod 6 6 100.0
total 66 70 94.2


line stmt bran cond sub pod time code
1             package Shodo;
2 5     5   149999 use 5.008005;
  5         17  
  5         174  
3 5     5   24 use strict;
  5         9  
  5         135  
4 5     5   25 use warnings;
  5         13  
  5         127  
5 5     5   5110 use Shodo::Suzuri;
  5         16  
  5         156  
6 5     5   2536 use Shodo::Hanshi;
  5         16  
  5         179  
7 5     5   5808 use Path::Tiny qw/path/;
  5         78617  
  5         2310  
8              
9             our $VERSION = "0.08";
10              
11             sub new {
12 5     5 1 37 my ($class, %args) = @_;
13 5 100       48 my $self = bless {
14             template => $args{template},
15             document_root => $args{document_root} ? path($args{document_root}) : path('.'),
16             }, $class;
17 5         221 $self->{stock} = '';
18 5         78 $self;
19             }
20              
21             sub template {
22 5     5 1 11 my ($self, $tmpl) = @_;
23 5 50       60 return $self->{template} unless $tmpl;
24 0         0 $self->{template} = $tmpl;
25 0         0 return $self->{template};
26             }
27              
28             sub document_root {
29 10     10 1 21 my ($self, $path) = @_;
30 10 100       181 return $self->{document_root} unless $path;
31 1         7 $self->{document_root} = path($path);
32 1         53 return $self->{document_root};
33             }
34              
35             sub new_suzuri {
36 5     5 1 899 my ($self, $description) = @_;
37 5         21 my $hanshi = Shodo::Hanshi->new(
38             template => $self->template,
39             );
40 5         23 return Shodo::Suzuri->new(
41             hanshi => $hanshi,
42             description => $description,
43             document_root => $self->document_root
44             );
45             }
46              
47             sub stock {
48 5     5 1 36 my ($self, $doc) = @_;
49 5 100       32 return $self->{stock} unless $doc;
50 2         10 $self->{stock} .= $doc;
51 2         8 return $self->{stock};
52             }
53              
54             sub write {
55 2     2 1 9 my ($self, $filename) = @_;
56 2 50       8 Carp::croak "Document root is not direcotry: " . $self->document_root unless( -d $self->document_root );
57 2         82 my $file = $self->document_root->child($filename);
58 2         99 $file->spew_utf8( $self->stock );
59 2         4473 $self->{stock} = '';
60             }
61              
62             1;
63             __END__