File Coverage

blib/lib/Nile/Config.pm
Criterion Covered Total %
statement 3 3 100.0
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 4 4 100.0


line stmt bran cond sub pod time code
1             # Copyright Infomation
2             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3             # Author : Dr. Ahmed Amin Elsheshtawy, Ph.D.
4             # Website: https://github.com/mewsoft/Nile, http://www.mewsoft.com
5             # Email : mewsoft@cpan.org, support@mewsoft.com
6             # Copyrights (c) 2014-2015 Mewsoft Corp. All rights reserved.
7             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8             package Nile::Config;
9              
10             our $VERSION = '0.55';
11             our $AUTHORITY = 'cpan:MEWSOFT';
12              
13             =pod
14              
15             =encoding utf8
16              
17             =head1 NAME
18              
19             Nile::Config - Configuration file manager.
20              
21             =head1 SYNOPSIS
22            
23             # get the app config object
24             $config = $self->app->config;
25            
26             # get a new config object
27             $config = $self->app->config->new;
28            
29             # keep sort order when reading and writing the xml file data. default is off.
30             #$config->keep_order(1);
31              
32             # load config file from the configuration folder, file extension is xml.
33             $config->load("config");
34              
35             # load and append another configuration file
36             $config->add_file("admins");
37            
38             # get config variables
39             say $config->get("admin/user");
40             say $config->get("admin/password");
41            
42             # get config variable, if not found return the optional provided default value.
43             $var = $config->get($name, $default);
44              
45             # automatic getter support
46             say $config->email; # same as $config->get('email');
47              
48             # get a group of config variables.
49             @list = $config->list(@names);
50              
51             # delete config variables from memory, changes will apply when saving file.
52             $config->delete(@names);
53              
54             # set config variables.
55             $config->set("admin", 'username');
56             $config->set(%vars);
57              
58             # automatic setter support
59             $config->email('ahmed@mewsoft.com'); # same as $config->set('email', 'ahmed@mewsoft.com');
60            
61             # save changes to file.
62             $config->save();
63              
64             # write to another output file.
65             $config->save($file);
66              
67             =head1 DESCRIPTION
68              
69             Nile::Config - Configuration file manager.
70              
71             Configuration files are xml files stored in the application config folder. You can load and manage any number
72             of configuration files.
73              
74             This class extends L<Nile::XML> class, therefore all methods from L<Nile::XML> is accessable to this object.
75              
76             =cut
77              
78 1     1   5 use Nile::Base;
  1         1  
  1         8  
79             extends 'Nile::XML';
80             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
81             around 'load' => sub {
82             my ($orig, $self, $file) = @_;
83             return $self->$orig($self->app->file->catfile($self->app->var->get("config_dir"), $file));
84             };
85             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
86              
87             =pod
88              
89             =head1 Bugs
90              
91             This project is available on github at L<https://github.com/mewsoft/Nile>.
92              
93             =head1 HOMEPAGE
94              
95             Please visit the project's homepage at L<https://metacpan.org/release/Nile>.
96              
97             =head1 SOURCE
98              
99             Source repository is at L<https://github.com/mewsoft/Nile>.
100              
101             =head1 SEE ALSO
102              
103             See L<Nile> for details about the complete framework.
104              
105             =head1 AUTHOR
106              
107             Ahmed Amin Elsheshtawy, احمد امين الششتاوى <mewsoft@cpan.org>
108             Website: http://www.mewsoft.com
109              
110             =head1 COPYRIGHT AND LICENSE
111              
112             Copyright (C) 2014-2015 by Dr. Ahmed Amin Elsheshtawy احمد امين الششتاوى mewsoft@cpan.org, support@mewsoft.com,
113             L<https://github.com/mewsoft/Nile>, L<http://www.mewsoft.com>
114              
115             This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
116              
117             =cut
118              
119             1;