remove use of yada yada
[chaz/homebank2ledger] / lib / App / HomeBank2Ledger / Formatter.pm
1 package App::HomeBank2Ledger::Formatter;
2 # ABSTRACT: Abstract class for formatting a ledger
3
4 =head1 SYNOPSIS
5
6 my $formatter = App::HomeBank2Ledger::Formatter->new(
7 type => 'ledger',
8 );
9 print $formatter->format($ledger);
10
11 =head1 DESCRIPTION
12
13 This class formats L<ledger data|App::HomeBank2Ledger::Ledger> as for a file.
14
15 =head1 SEE ALSO
16
17 =for :list
18 * L<App::HomeBank2Ledger::Formatter::Beancount>
19 * L<App::HomeBank2Ledger::Formatter::Ledger>
20
21 =cut
22
23 use warnings;
24 use strict;
25
26 use Module::Load;
27 use Module::Pluggable search_path => [__PACKAGE__],
28 sub_name => 'available_formatters';
29
30 our $VERSION = '9999.999'; # VERSION
31
32 sub _croak { require Carp; Carp::croak(@_) }
33
34 =method new
35
36 $formatter = App::HomeBank2Ledger::Formatter->new(type => $format);
37
38 Construct a new formatter object.
39
40 =cut
41
42 sub new {
43 my $class = shift;
44 my %args = @_;
45
46 my $package = __PACKAGE__;
47
48 if ($class eq $package and my $type = $args{type}) {
49 # factory
50 for my $formatter ($class->available_formatters) {
51 next if lc($formatter) ne lc("${package}::${type}");
52 $class = $formatter;
53 load $class;
54 last;
55 }
56 _croak('Invalid formatter type') if $class eq $package;
57 }
58
59 return bless {%args}, $class;
60 }
61
62 =method format
63
64 $str = $formatter->format($ledger);
65
66 Do the actual formatting of ledger data into a serialized form.
67
68 This must be overridden by subclasses.
69
70 =cut
71
72 sub format {
73 die "Unimplemented\n";
74 }
75
76 =attr type
77
78 Get the type of formatter.
79
80 =attr name
81
82 Get the name or title of the ledger.
83
84 =attr file
85
86 Get the filepath where the ledger data came from.
87
88 =attr account_width
89
90 Get the number of characters to use for the account column.
91
92 =cut
93
94 sub type { shift->{type} }
95 sub name { shift->{name} }
96 sub file { shift->{file} }
97 sub account_width { shift->{account_width} || 40 }
98
99 1;
This page took 0.034435 seconds and 4 git commands to generate.