line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Fix::import_from_string; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
108587
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
6
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.2020'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
11
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
8
|
1
|
|
|
1
|
|
1024
|
use Catmandu::Util::Path qw(as_path); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
65
|
|
9
|
1
|
|
|
1
|
|
433
|
use Catmandu; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
5
|
|
10
|
1
|
|
|
1
|
|
279
|
use namespace::clean; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
11
|
1
|
|
|
1
|
|
820
|
use Catmandu::Fix::Has; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
with 'Catmandu::Fix::Builder'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has path => (fix_arg => 1); |
16
|
|
|
|
|
|
|
has name => (fix_arg => 1); |
17
|
|
|
|
|
|
|
has opts => (fix_opt => 'collect'); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub _build_fixer { |
20
|
6
|
|
|
6
|
|
56
|
my ($self) = @_; |
21
|
6
|
|
|
|
|
21
|
my $name = $self->name; |
22
|
6
|
|
|
|
|
52
|
my $opts = $self->opts; |
23
|
|
|
|
|
|
|
as_path($self->path) |
24
|
|
|
|
|
|
|
->updater( |
25
|
6
|
|
|
6
|
|
46
|
if_string => sub {Catmandu->import_from_string($_[0], $name, %$opts)} |
26
|
6
|
|
|
|
|
33
|
); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
1; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
__END__ |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=pod |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=encoding utf8 |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 NAME |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Catmandu::Fix::import_from_string - Import data from a string into an array ref, using a named importer. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 SYNOPSIS |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
#BEFORE: { 'json' => '[{"name":"Nicolas"}]' } |
44
|
|
|
|
|
|
|
#AFTER: { 'json' => [{"name":"Nicolas"}] } |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
import_from_string('json','JSON') |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
#BEFORE: { record => qq(first_name;name\nNicolas;Franck\nPatrick;Hochstenbach\n) } |
49
|
|
|
|
|
|
|
#AFTER: { record => [{ "first_name" => "Nicolas",name => "Franck" },{ "first_name" => "Patrick",name => "Hochstenbach" }] } |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
import_from_string('record','CSV', 'sep_char' => ';') |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 DESCRIPTION |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head2 import_from_string( PATH, NAME [, IMPORT_OPTIONS ] ) |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
This fix uses the function import_from_string of the package L<Catmandu>, but requires the NAME of the importer. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
It always returns an array of hashes. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=over 4 |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=item PATH |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=item NAME |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
name of the importer to use. As usual in Catmandu, one can choose: |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
* full package name of the importer (e.g. 'Catmandu::Importer::JSON') |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
* short package name of the importer (e.g. 'JSON') |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
* name of the importer as declared in the Catmandu configuration |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=item IMPORT_OPTIONS |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
extra options for the named importer |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=back |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 AUTHOR |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Nicolas Franck, C<< <nicolas.franck at ugent.be> >> |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 SEE ALSO |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
L<Catmandu::Fix>, L<Catmandu::Importer> |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |