我正在嘗試使用mochiweb編寫一些應用程序。應用程序樹:erlang -import如何工作?
tree
.
├── aniaggregator2.iml
├── deps
│ └── mochiweb
│ ├── CHANGES.md
│ ├── doc
│ ├── ebin
│ │ ├── ....
│ │ ├── mochiweb_html.beam
│ │ ├── ....
│ ├── examples
│ │ ├── ......
│ ├── include
│ │ └── ......
│ ├── LICENSE
│ ├── Makefile
│ ├── README
│ ├── rebar
│ ├── rebar.config
│ ├── scripts
│ │ ├── entities.erl
│ │ └── new_mochiweb.erl
│ ├── src
│ │ ├── .....
│ │ ├── mochiweb_html.erl
│ │ ├── .....
│ ├── support
│ │ ├── .....
│ └── test
│ .....
├── ebin
│ ├── aniaggregator.app
│ ├── aniaggregator_app.beam
│ ├── aniaggregator.beam
│ ├── aniaggregator_deps.beam
│ ├── aniaggregator_sup.beam
│ └── aniaggregator_web.beam
├── LICENSE
├── Makefile
├── priv
│ └── www
│ └── index.html
├── README.md
├── rebar
├── rebar.config
├── src
│ ├── .....
│ └── parsers
│ ├── default_parser.beam
│ ├── default_parser.erl
│ ├── default_parser_tests.beam
│ ├── default_parser_tests.erl
│ └── erl_crash.dump
└── start-dev.sh
default_parser.erl看起來像
-module(default_parser).
-author("psih").
-import(mochiweb_html, [parse/1]).
%% API
-export([parse_from_url/1, fetch_names_from_animelist/0]).
parse_from_url(Url) ->
{ok, {Status, Headers, Body}} = httpc:request(Url),
Status.
fetch_names_from_smth() ->
Url = "some_url",
{ok, {Status, Headers, Body}} = httpc:request(Url),
{String, Attributes, Other} = parse(Body),
Attributes.
default_parser_tests.erl樣子:
-module(default_parser_tests).
-include_lib("eunit/include/eunit.hrl").
start() ->
application:start(inets),
ok.
stop(_) ->
application:stop(inets),
ok.
do_some_testing(_) ->
erlang:display(default_parser:fetch_names_from_smth()),
[?_assert(true =:= true)].
do_some_test_() ->
{"Performs some default parsing stuff!",
{setup,
fun start/0,
fun stop/1,
fun do_some_testing/1
}
}.
的!erlc default_parser.erl && erlc default_parser_tests.erl && erl -pa -noshell -eval "eunit:test(default_parser)" -s init stop
輸出是一樣的東西:
*** instantiation of subtests failed ***
::error:undef
in function mochiweb_html1:parse/1
called as parse(....)
in call from default_parser:fetch_names_from_smth/0
in call from default_parser_tests:do_some_testing/1
=======================================================
Failed: 0. Skipped: 0. Passed: 0.
One or more tests were cancelled.
所以,我的問題是 - 我如何從mochiweb *導入模塊到我的特定應用程序?我也會很感激任何有關erlang模塊發現算法的文檔/文章的鏈接。
你不需要使用導入,你可能不應該:http:// www.erlang.se/doc/programming_rules.shtml#HDR26 – kjw0188