NAME

Nile::Setting - Application global settings database table manager.

SYNOPSIS

# 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);

DESCRIPTION

Nile::Setting - Application global settings database table manager.

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);

setting_table_name()

# 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.

setting_name_column()

# 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.

setting_value_column()

# 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()

# 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.

unload()

# 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.

vars()

# 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()

# 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()

# 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.

list()

# get a list of settings variables.
@vars = $setting->list(@names);

Returns a list of settings variables.

keys()

# returns all settings names.
@names = $setting->keys;

Returns all settings names.

exists()

# check if a setting variable exist or not.
$found = $setting->exists($name);

Check if a setting variable exist or not.

delete()

# delete settings from memory and database table.
$setting->delete(@names);

Delete a list of settings from memory and database table..

clear()

# 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.

object()

# 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.

Bugs

This project is available on github at https://github.com/mewsoft/Nile.

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/Nile.

SOURCE

Source repository is at https://github.com/mewsoft/Nile.

SEE ALSO

See Nile for details about the complete framework.

AUTHOR

Ahmed Amin Elsheshtawy, احمد امين الششتاوى <mewsoft@cpan.org> Website: http://www.mewsoft.com

COPYRIGHT AND LICENSE

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.