How do I use a module defined in lib/ folder of Phoenix project? - module

I've created a Module inside the lib/, more specifically lib/my_namespace/test_module.exs.
This is all that is defined within it:
defmodule MyNamespace.TestModule do
def test do
"This is a test"
end
end
Calling the test() function of this module within a Phoenix Controller renders an error.
** (UndefinedFunctionError) function MyNamespace.TestModule.test/0 is undefined (module MyNamespace.TestModule is not available)
MyNamespace.TestModule.test()
According to the Elixir 1.2.0 Changelog, it is my understanding that Elixir is meant to reload the code in lib/ directory, so my assumption is that I wasn't going to need to do anything else.
I'm obviously wrong, and my own research hasn't been yielding anything promising. The only thing I've gathered is that my module isn't getting onto the ?loadpath? and I'm not to sure what to change so it is on the loadpath.
Could someone lend a hand and also point me in the direction of what documentation I should be reading?
Thanks in advance.

.exs files are meant for scripting and are not compiled to bytecode by mix along with the rest of the project. You should rename lib/my_namespace/test_module.exs to lib/my_namespace/test_module.ex if you want to be able to access modules defined in it from your application.

Related

How can i get a list of modules

I have a WPF application built on top of PRISM.
When i tries to list module before loaded modules when find modules,I use dicitonary find module,but i dont look any module in modulecategory.
Any suggestions on how I can do this?
Thanks in advance
The easiest thing to do is to name your module assemblies in a special way, like MySomething.module.dll and then look for these when putting together the module catalog. There once was a module catalog implementation around on codeplex that allowed to pass a search pattern including subfolders... link

Eagerloading files in directories inside the app folder in Rails 3. How is it done?

I read this:
If you add a dir directly under app/
Do nothing. All files in this dir are eager loaded in production and
lazy loaded in development by default.
If you add a dir under app/something/
(e.g. app/models/concerns/, app/models/products/)
Ask: do I want to namespace modules and classes inside my new dir? For
example in app/models/products/ you would need to wrap your class in
module Products.
If the answer is yes, do nothing. It will just work.
If the answer is no, add config.autoload_paths += %W(
#{config.root}/app/models/products )
I want to know how Rails does this. How does it:
Load the file inside a folder (named folder_nest) in the app folder only if the contents of that file are wrapped in a module named after that folder (folder_nest module). How does this happen?
There must be some logic that says: "if the thing inside of app is a file, eager load it. If it's a folder, only load the contents of said folder if it's wrapped in a module named after said folder."
Anyone know where this logic is? How do I read Rails source code?
Also, is config/initializers eagerly loaded? Where is that logic?
Well, looks like you have a lot of questions best answered by the one question "How do I read Rails source code"
Personally, I do something like the following from the command-line:
subl `bundle show rails`
and then use the text editor (sublime in this case, textmate also works) + search, just read the code. Sometimes I'll insert "puts" statements in there to make sure I'm reading the right code and run it just to be sure.
You can answer most of your own questions about the initialization sequence, etc, that way.

Generate NGC for custom VHDL module in IPCore Xilinx

I am trying to implement a custom IPCore for the Zedboard. In my User_Logic I am including a component (My_Module) from the VHDL module (My_Module.vhd) which I wrote as part of the ISE project. But when I come to generate the bitstream for my design in PlanAhead it asks for the My_Module.ngc as if it is treating it as a blackbox. I though the NGC was only required when using CoreGen IPCores, but it seems it also wants it for any VHDL module included as I guess this is a 'black box'.
The issue is how do I create a NGC file from the VHDL for this module, which is part of an ISE project. As I can't find any function in ISE that allows you to just generate the netlist for one VHDL module. Or can I export this module out into a separate ISE project and then synthesise it to get the .ngc?
Many thanks
Sam
Are you sure you've typed the module name in exactly the same way both in your module .vhd file, and in the file using the module as a component?
Under normal circumstances, if your project includes the module as a .vhd file, it'll just be synthesized along with the rest of your sources - I did a quick test and renamed a component in one of my own projects, and got a complaint about a possibly missing .ngc file (this was in ISE, and not in PlanAhead though).
So the answer is to generate the NGC files by making the modules you want "the top module" you can then run the synthesis to generate the individual NGC. Then proceed as normal when adding IP to a PCore. So adding these NGC files to the netlist folder and modifying the BBD file and all that!
As a note for completion to get the module working you need to set the synthesis setting "Xilinx Specefic" -> and disable "add io buffers"
Are you including My_Module.vhd as a source file in your ISE Project? If you are, check to see that the ISE project doesn't have a yellow question mark next to the My_Module component. If it does, then it needs more information about that component. You should see a little icon with the letters VHD in it in your ISE Implementation Hierarchy View.

How to run the sha2.c of polarssl

I was trying to use the sha2.c file from polarssl at this link,
https://polarssl.org/sha-256-source-code
I am actually quite a newbie to this, but I was able to get this on Eclipse and when I tried to build it, it gives the error
c:/mingw/x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o):crt0_c.c:(.text+0x3d): undefined reference to `WinMain'
do I have to pass some kind of data in the arguments? how can I find out how to use it?
The problem is not in the source file you downloaded, but the fact that you need to make 'an application'. Eclipse cannot compile 'just some functionality' unless you instruct it to build a library. You will have to provide a WinMain / main function so that Windows knows what to do when you start the application.
That is what the compiler is complaining about, there is no main() functions it can compile into the application!
Easiest way to start is to start a Generic C Application in Eclipse and then add this sha2 source file and header to that project. The Generic C application project already has a main function you can work from..

Listing all calls from an erlang module

I'm an Erlang beginer and I'd like to find a way to list all the methods available for a given module. What's the best way?
In my case, the module is ejabberd_odbc.
You can call Modulename:module_info() to get information on the module in a proplist form. To get exports only, call Modulename:module_info(exports).
I'm always checking the exports section in the source of the module.
There is a tool you can install called edoc, whose manual is at: http://www.erlang.org/doc/man/edoc.html This allows javadoc style documentation to be generated for Erlang modules.
Also there is ejabberd_odbc documentation at: http://www.process-one.net/docs/ejabberd/devdoc/trunk/ejabberd_odbc.html