diff options
author | serge <[email protected]> | 2013-01-10 09:07:38 -0500 |
---|---|---|
committer | Serge Aleynikov <[email protected]> | 2013-01-14 13:24:41 -0500 |
commit | d1d834820ddaba4fa31e6ab6d07a96ac7cc6d999 (patch) | |
tree | 9dd256e5390bc9845cfd1ccb094845a904bbb911 /lib | |
parent | 9f461fbaf0be7aba7c0b8b89be1f0b6f1141b7a5 (diff) | |
download | otp-d1d834820ddaba4fa31e6ab6d07a96ac7cc6d999.tar.gz otp-d1d834820ddaba4fa31e6ab6d07a96ac7cc6d999.tar.bz2 otp-d1d834820ddaba4fa31e6ab6d07a96ac7cc6d999.zip |
Add application:get_key/3
The new function provides a default value for a configuration
parameter.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/kernel/doc/src/application.xml | 4 | ||||
-rw-r--r-- | lib/kernel/src/application.erl | 16 | ||||
-rw-r--r-- | lib/kernel/test/application_SUITE.erl | 13 |
3 files changed, 29 insertions, 4 deletions
diff --git a/lib/kernel/doc/src/application.xml b/lib/kernel/doc/src/application.xml index 51a3311ec2..3513e2b592 100644 --- a/lib/kernel/doc/src/application.xml +++ b/lib/kernel/doc/src/application.xml @@ -108,12 +108,14 @@ <func> <name name="get_env" arity="1"/> <name name="get_env" arity="2"/> + <name name="get_env" arity="3"/> <fsummary>Get the value of a configuration parameter</fsummary> <desc> <p>Returns the value of the configuration parameter <c><anno>Par</anno></c> for <c><anno>Application</anno></c>. If the application argument is omitted, it defaults to the application of the calling - process.</p> + process. If <c><anno>Def</anno></c> value is provided, it is returned + when no configuration parameter <c><anno>Par</anno></c> is defined.</p> <p>If the specified application is not loaded, or the configuration parameter does not exist, or if the process executing the call does not belong to any application, diff --git a/lib/kernel/src/application.erl b/lib/kernel/src/application.erl index 9b7c4aa7b8..4e65883be7 100644 --- a/lib/kernel/src/application.erl +++ b/lib/kernel/src/application.erl @@ -23,7 +23,7 @@ which_applications/0, which_applications/1, loaded_applications/0, permit/2]). -export([set_env/3, set_env/4, unset_env/2, unset_env/3]). --export([get_env/1, get_env/2, get_all_env/0, get_all_env/1]). +-export([get_env/1, get_env/2, get_env/3, get_all_env/0, get_all_env/1]). -export([get_key/1, get_key/2, get_all_key/0, get_all_key/1]). -export([get_application/0, get_application/1, info/0]). -export([start_type/0]). @@ -264,6 +264,20 @@ get_env(Key) -> get_env(Application, Key) -> application_controller:get_env(Application, Key). +-spec get_env(Application, Par, Def) -> Val when + Application :: atom(), + Par :: atom(), + Def :: term(), + Val :: term(). + +get_env(Application, Key, Def) -> + case get_env(Application, Key) of + {ok, Val} -> + Val; + undefined -> + Def + end. + -spec get_all_env() -> Env when Env :: [{Par :: atom(), Val :: term()}]. diff --git a/lib/kernel/test/application_SUITE.erl b/lib/kernel/test/application_SUITE.erl index f469a0af98..412a969b13 100644 --- a/lib/kernel/test/application_SUITE.erl +++ b/lib/kernel/test/application_SUITE.erl @@ -27,7 +27,7 @@ otp_1586/1, otp_2078/1, otp_2012/1, otp_2718/1, otp_2973/1, otp_3002/1, otp_3184/1, otp_4066/1, otp_4227/1, otp_5363/1, otp_5606/1, - start_phases/1, get_key/1, + start_phases/1, get_key/1, get_env/1, permit_false_start_local/1, permit_false_start_dist/1, script_start/1, nodedown_start/1, init2973/0, loop2973/0, loop5606/1]). @@ -49,7 +49,7 @@ all() -> [failover, failover_comp, permissions, load, load_use_cache, {group, reported_bugs}, start_phases, script_start, nodedown_start, permit_false_start_local, - permit_false_start_dist, get_key, + permit_false_start_dist, get_key, get_env, {group, distr_changed}, config_change, shutdown_func, shutdown_timeout]. groups() -> @@ -1503,6 +1503,15 @@ loop5606(Pid) -> Pid ! {self(), Res} end. +get_env(suite) -> []; +get_env(doc) -> + ["Tests get_env/* functions"]; +get_env(Conf) when is_list(Conf) -> + ?line {ok, _} = application:get_env(kernel, error_logger), + ?line undefined = application:get_env(undefined_app, a), + ?line undefined = application:get_env(kernel, error_logger_xyz), + ?line default = application:get_env(kernel, error_logger_xyz, default), + ok. %%----------------------------------------------------------------- %% Should be started in a CC view with: |