use Exporter qw(import);
use Scalar::Util qw(refaddr);
use Time::Piece;
+use XML::Entities;
use XML::Parser::Lite;
our $VERSION = '9999.999'; # VERSION
our @EXPORT_OK = qw(parse_string parse_file);
-sub _croak { require Carp; Carp::croak(@_) }
-sub _usage { _croak("Usage: @_\n") }
-
my %ACCOUNT_TYPES = (
0 => 'none',
1 => 'bank',
11 => 'directdebit',
);
+sub _croak { require Carp; Carp::croak(@_) }
+sub _usage { _croak("Usage: @_\n") }
+
=method new
$homebank = File::HomeBank->new(string => $str);
$transations = $homebank->sorted_transactions;
-Get an arrayref of transactions sorted by date (earliest first).
+Get an arrayref of transactions sorted by date (oldest first).
=cut
shift;
my $node = shift;
my %attr = @_;
+
+ # decode all attribute values
+ for my $key (keys %attr) {
+ $attr{$key} = _decode_xml_entities($attr{$key});
+ }
+
if ($node eq 'properties') {
$attr{currency} = delete $attr{curr} if $attr{curr};
%properties = %attr;
};
}
+sub _decode_xml_entities {
+ my $str = shift;
+ # decoding entities can be extremely slow, so don't bother if it doesn't look like there are any
+ # entities to decode
+ return $str if $str !~ /&(?:#\d+)|[A-Za-z0-9]+;/;
+ return XML::Entities::decode('all', $str);
+}
+
sub _rdn_to_unix_epoch {
my $rdn = shift;
my $jan01_1970 = 719163;