Version 0.001
[chaz/homebank2ledger] / lib / App / HomeBank2Ledger / Formatter.pm
1 package App::HomeBank2Ledger::Formatter;
2 # ABSTRACT: Abstract class for formatting a ledger
3
4
5 use warnings;
6 use strict;
7
8 use Module::Load;
9 use Module::Pluggable search_path => [__PACKAGE__],
10 sub_name => 'available_formatters';
11
12 our $VERSION = '0.001'; # VERSION
13
14 sub _croak { require Carp; Carp::croak(@_) }
15
16
17 sub new {
18 my $class = shift;
19 my %args = @_;
20
21 my $package = __PACKAGE__;
22
23 if ($class eq $package and my $type = $args{type}) {
24 # factory
25 for my $formatter ($class->available_formatters) {
26 next if lc($formatter) ne lc("${package}::${type}");
27 $class = $formatter;
28 load $class;
29 last;
30 }
31 _croak('Invalid formatter type') if $class eq $package;
32 }
33
34 return bless {%args}, $class;
35 }
36
37
38 sub format {
39 ...
40 }
41
42
43 sub type { shift->{type} }
44 sub name { shift->{name} }
45 sub file { shift->{file} }
46 sub account_width { shift->{account_width} || 40 }
47
48 1;
49
50 __END__
51
52 =pod
53
54 =encoding UTF-8
55
56 =head1 NAME
57
58 App::HomeBank2Ledger::Formatter - Abstract class for formatting a ledger
59
60 =head1 VERSION
61
62 version 0.001
63
64 =head1 SYNOPSIS
65
66 my $formatter = App::HomeBank2Ledger::Formatter->new(
67 type => 'ledger',
68 );
69 print $formatter->format($ledger);
70
71 =head1 DESCRIPTION
72
73 This class formats L<ledger data|App::HomeBank2Ledger::Ledger> as for a file.
74
75 =head1 ATTRIBUTES
76
77 =head2 type
78
79 Get the type of formatter.
80
81 =head2 name
82
83 Get the name or title of the ledger.
84
85 =head2 file
86
87 Get the filepath where the ledger data came from.
88
89 =head2 account_width
90
91 Get the number of characters to use for the account column.
92
93 =head1 METHODS
94
95 =head2 new
96
97 $formatter = App::HomeBank2Ledger::Formatter->new(type => $format);
98
99 Construct a new formatter object.
100
101 =head2 format
102
103 $str = $formatter->format($ledger);
104
105 Do the actual formatting of ledger data into a serialized form.
106
107 This must be overridden by subclasses.
108
109 =head1 SEE ALSO
110
111 =over 4
112
113 =item *
114
115 L<App::HomeBank2Ledger::Formatter::Beancount>
116
117 =item *
118
119 L<App::HomeBank2Ledger::Formatter::Ledger>
120
121 =back
122
123 =head1 BUGS
124
125 Please report any bugs or feature requests on the bugtracker website
126 L<https://github.com/chazmcgarvey/homebank2ledger/issues>
127
128 When submitting a bug or request, please include a test-file or a
129 patch to an existing test-file that illustrates the bug or desired
130 feature.
131
132 =head1 AUTHOR
133
134 Charles McGarvey <chazmcgarvey@brokenzipper.com>
135
136 =head1 COPYRIGHT AND LICENSE
137
138 This software is Copyright (c) 2019 by Charles McGarvey.
139
140 This is free software, licensed under:
141
142 The MIT (X11) License
143
144 =cut
This page took 0.037753 seconds and 4 git commands to generate.