Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/choptastic/erlias
Erlang Alias Module Creator
https://github.com/choptastic/erlias
Last synced: 21 days ago
JSON representation
Erlang Alias Module Creator
- Host: GitHub
- URL: https://github.com/choptastic/erlias
- Owner: choptastic
- License: mit
- Created: 2020-04-14T21:50:06.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-08-06T18:21:47.000Z (over 1 year ago)
- Last Synced: 2024-03-14T20:22:03.303Z (8 months ago)
- Language: Erlang
- Size: 10.7 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
erlias
=====Compile an Alias Module for Erlang
About this Library
==================(This was originally a part of [sql_bridge](https://github.com/choptastic/sql_bridge),
but has been split off into its own library for others to use, if they want.)There are a number of other Erlang module alias libraries out there, but they
all appear to be parse transforms, where you must compile your modules with
the parse transform. This gives an interesting level of flexibility, where you
can have different module aliases for different calling modules.This is not that.
This is not a parse transform. This creates a new globally accessible module.
And you do not have to modify your source code to use this in any way, or
recompile any modules to make it work. This new module simply maps from the
new module to the original module.This was originally built for `sql_bridge` so that instead of calling
`sql_bridge:q(Query)`
you could simply call
`db:q(Query)`
Usage
=====Sometime (probably during application startup), call the following
```erlang
erlias:build(my_super_long_module_name, short).
```This will compile a new module called `short` that takes the exports from
`my_super_long_module_name` and forwards them to the long module.Instead of calling:
```
my_super_long_module_name:some_function().
```You can now call
```
short:some_function().
```Because `short` is a new globally accessible module, it can be called from
any module or from the Erlang shell.How it works
------------
It literally just looks at the exports of `my_super_long_module_name` and
creates a mapper module:For example, if `some_function()` is the only exported function in
`my_super_long_module_name`, the true implementation of `short` would be this:```
-module(short).
-export([some_function/0]).some_function() ->
my_super_long_module_name:some_function().
```Another Function
----------------You can also call `erlias:build_text(OriginalMod, NewModule)` and this will
return the string of the generated module (it won't compile or load the module,
just give you the text).Author
======[Jesse Gumm](http://jessegumm.com)
MIT Licensed