Nile::Setting - Application global settings database table manager.
# get setting object instance $setting = $self->me->setting; # load settings from database to the setting object. $setting->load("settings", "name", "value"); # get settings say $setting->get("email"); say $setting->get("website", "default value"); # automatic getter support say $setting->email; # same as $setting->get('email'); # set settings variables. $setting->set("page_views", $count); $setting->set(%vars); # automatic setter support $setting->email('ahmed@mewsoft.com'); # same as $setting->set('email', 'ahmed@mewsoft.com'); # delete settings from memory and database table. $setting->delete(@names);
This class to manage an optional application shared settings database table the same way you share the var and config object.
Example of a suggested database table structure.
CREATE TABLE settings ( name varchar(255), # name_column value varchar(255) # value_column, change type to TEXT if needed ) ENGINE=InnoDB default CHARACTER SET=utf8;
Then you need to call the load setting once at the start of the application after you connect to the database.
# get setting object instance $setting = $self->me->setting; # load settings from database to the setting object. $setting->load("settings", "name", "value");
Now you can get, set and delete the settings anywhere in your application.
# get settings say $setting->get("email"); say $setting->get("website", "default value"); # automatic getter support say $setting->email; # same as $setting->get('email'); # set settings variables. $setting->set("page_views", $count); $setting->set(%vars); # automatic setter support $setting->email('ahmed@mewsoft.com'); # same as $setting->set('email', 'ahmed@mewsoft.com'); # delete settings from memory and database table. $setting->delete(@names);
# set database settings table name $setting->setting_table_name("settings"); # get database settings table name $setting->setting_table_name;
Get and set the settings database table name.
# set settings table column name for the 'name_column'. $setting->setting_name_column("name"); # get settings table column name for the 'name_column'. $setting->setting_name_column;
Get and set the settings database table column name.
# set settings table column name for the 'value_column'. $setting->setting_value_column("value"); # get settings table column name for the 'value_column'. $setting->setting_value_column;
Get and set the settings database table column value_column.
# load settings from database to the setting object. $setting->load($db_table, $name_column, $value_column);
Load the settings from database table to the setting object. This method can be chained.
# clears all settings from memory. $setting->unload;
Resets the setting object and clear all settings from memory. This does not update the database table. This method can be chained.
# get all settings as a hash or a hash ref. %vars = $setting->vars(); $vars = $setting->vars();
Returns all settings as a hash or a hash reference.
# set settings variables. $setting->set("page_views", $count); $setting->set(%vars); # automatic setter support $setting->email('ahmed@mewsoft.com'); # same as $setting->set('email', 'ahmed@mewsoft.com');
Set settings variables.
# get settings say $setting->get("email"); say $setting->get("website", "default value"); # automatic getter support say $setting->email; # same as $setting->get('email');
Returns settings variables.
# get a list of settings variables. @vars = $setting->list(@names);
Returns a list of settings variables.
# returns all settings names. @names = $setting->keys;
Returns all settings names.
# check if a setting variable exist or not. $found = $setting->exists($name);
Check if a setting variable exist or not.
# delete settings from memory and database table. $setting->delete(@names);
Delete a list of settings from memory and database table..
# delete all settings from memory and database table. $setting->clear(1);
Delete all settings from memory and database table. This can not be undone. You must pass a true value for the function as a confirmation that you want to do the job.
# get a new setting object #my $setting_obj = $setting->object; # load and manage settings table separately #$setting_obj->load("table", "name", "value");
Returns a new setting object. This allows to load individual setting table and work with them.
This project is available on github at https://github.com/mewsoft/Nile.
Please visit the project's homepage at https://metacpan.org/release/Nile.
Source repository is at https://github.com/mewsoft/Nile.
See Nile for details about the complete framework.
Ahmed Amin Elsheshtawy, احمد امين الششتاوى <mewsoft@cpan.org> Website: http://www.mewsoft.com
Copyright (C) 2014-2015 by Dr. Ahmed Amin Elsheshtawy احمد امين الششتاوى mewsoft@cpan.org, support@mewsoft.com, https://github.com/mewsoft/Nile, http://www.mewsoft.com
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Nile, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Nile
CPAN shell
perl -MCPAN -e shell install Nile
For more information on module installation, please visit the detailed CPAN module installation guide.