Skip to content
Browse files

Refactoring on the plugin_loader

  • Loading branch information...
1 parent 40bd1e8 commit 9c34ca6365cdfae79d50d888ad453d24d905786a @Gianfrancoalongi committed Dec 7, 2012
Showing with 16 additions and 14 deletions.
  1. +16 −14 run1/src/mrz_plugin_loader.erl
View
30 run1/src/mrz_plugin_loader.erl
@@ -3,13 +3,12 @@
-export([plugin_to_feature_name/1]).
-export([load_plugins/1]).
-find_plugins(Path) ->
- X_plugins = lists:map(fun filename:basename/1,
- filelib:wildcard(filename:join(Path,"x_plugin_*.erl"))),
- O_plugins = lists:map(fun filename:basename/1,
- filelib:wildcard(filename:join(Path,"o_plugin_*.erl"))),
- Y_plugins = lists:map(fun filename:basename/1,
- filelib:wildcard(filename:join(Path,"y_plugin_*.erl"))),
+find_plugins(SourcePath) ->
+ FB = fun filename:basename/1,
+ F = fun(Path,Prefix) -> filelib:wildcard(filename:join(Path,Prefix++"_plugin_*.erl")) end,
+ X_plugins = lists:map(FB,F(SourcePath,"x")),
+ O_plugins = lists:map(FB,F(SourcePath,"o")),
+ Y_plugins = lists:map(FB,F(SourcePath,"y")),
{X_plugins,O_plugins,Y_plugins}.
%% Format is {x,o,y}_plugin_NAME
@@ -31,15 +30,18 @@ try_load_plugins(PluginList) ->
{file,_} ->
[ Module | Acc];
false ->
- case code:load_file(Module) of
- {error,_} ->
- Acc;
- {module,_} ->
- [ Module | Acc]
- end
+ maybe_load_file(Module,Acc)
end
end,
[],
PluginList).
-
+
+maybe_load_file(Module,Acc) ->
+ case code:load_file(Module) of
+ {error,_} ->
+ Acc;
+ {module,_} ->
+ [ Module | Acc]
+ end.
+

0 comments on commit 9c34ca6

Please sign in to comment.
Something went wrong with that request. Please try again.