| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package XAS::Lib::Mixins::Configs; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
830
|
use Try::Tiny; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
72
|
|
|
6
|
1
|
|
|
1
|
|
642
|
use Config::IniFiles; |
|
|
1
|
|
|
|
|
13819
|
|
|
|
1
|
|
|
|
|
48
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use XAS::Class |
|
9
|
1
|
|
|
|
|
8
|
debug => 0, |
|
10
|
|
|
|
|
|
|
version => $VERSION, |
|
11
|
|
|
|
|
|
|
base => 'XAS::Base', |
|
12
|
|
|
|
|
|
|
utils => ':validation dotid compress', |
|
13
|
|
|
|
|
|
|
mixins => 'load_config', |
|
14
|
1
|
|
|
1
|
|
8
|
; |
|
|
1
|
|
|
|
|
2
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
|
17
|
|
|
|
|
|
|
# Public Methods |
|
18
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub load_config { |
|
21
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
22
|
0
|
|
|
|
|
|
my ($filename, $handle) = validate_params(\@_, [ |
|
23
|
|
|
|
|
|
|
{ optional => 1, isa => 'Badger::Filesystem::File', default => $self->env->cfg_file }, |
|
24
|
|
|
|
|
|
|
{ optional => 1, default => 'cfg' }, |
|
25
|
|
|
|
|
|
|
]); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# really... using carp() as an exception handler is lame |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
local $SIG{__WARN__} = sub { |
|
30
|
0
|
|
|
0
|
|
|
my $error = shift; |
|
31
|
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
my ($reason) = $error =~ /(.*)at\s+/; |
|
33
|
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
$self->throw_msg( |
|
35
|
|
|
|
|
|
|
dotid($self->class) . '.load_config.badini', |
|
36
|
|
|
|
|
|
|
'config_badini', |
|
37
|
|
|
|
|
|
|
$filename->path, |
|
38
|
|
|
|
|
|
|
$reason, |
|
39
|
|
|
|
|
|
|
); |
|
40
|
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
}; |
|
42
|
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
$self->{$handle} = Config::IniFiles->new(-file => $filename->path); |
|
44
|
|
|
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
|
unless (defined($self->{$handle})) { |
|
46
|
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
$self->throw_msg( |
|
48
|
|
|
|
|
|
|
dotid($self->class) . '.load_config.badini', |
|
49
|
|
|
|
|
|
|
'config_badini', |
|
50
|
|
|
|
|
|
|
$filename->path, |
|
51
|
|
|
|
|
|
|
compress(join('', @Config::IniFiles::errors)), |
|
52
|
|
|
|
|
|
|
); |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
|
59
|
|
|
|
|
|
|
# Private Methods |
|
60
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
__END__ |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 NAME |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
XAS::Lib::Mixins::Configs - A mixin for handling config files |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
use XAS::Class; |
|
73
|
|
|
|
|
|
|
version => '0.01', |
|
74
|
|
|
|
|
|
|
base => 'XAS::Base', |
|
75
|
|
|
|
|
|
|
mixin => 'XAS::Lib::Mixins::Configs', |
|
76
|
|
|
|
|
|
|
accessors => 'cfg', |
|
77
|
|
|
|
|
|
|
; |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
This mixin provides a standardized way to load .ini files. |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 METHODS |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 load_config($filename, $handle) |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
This method will load a .ini style configuration file. It uses the following |
|
88
|
|
|
|
|
|
|
parameters: |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=over 4 |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=item B<$filename> |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
The file name for the configuration file. |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=item B<$handle> |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
An optional name to the accessor that will access the |
|
99
|
|
|
|
|
|
|
L<Config::IniFiles|https://metacpan.org/pod/Config::IniFiles> |
|
100
|
|
|
|
|
|
|
object in the current self. This name defaults to 'cfg'. |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=back |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=over 4 |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item L<XAS|XAS> |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=back |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 AUTHOR |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Kevin L. Esteb, E<lt>kevin@kesteb.usE<gt> |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Copyright (C) 2014 Kevin L. Esteb |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
121
|
|
|
|
|
|
|
the terms of the Artistic License 2.0. For details, see the full text |
|
122
|
|
|
|
|
|
|
of the license at http://www.perlfoundation.org/artistic_license_2_0. |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=cut |