Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

switch from using `Erlang.module` syntax to `:module`

  • Loading branch information...
commit d4adc44c0b18de5f59f1dbb8ae99c5b8984a79f8 1 parent dc348af
Carlo Cabanilla authored April 15, 2012
16  src/cerebrate.ex
@@ -2,9 +2,9 @@ defmodule Cerebrate do
2 2
   @behavior :application
3 3
 
4 4
   def start() do
5  
-    Erlang.application.start :dnssd
6  
-    Erlang.application.start :cowboy
7  
-    Erlang.application.start __MODULE__
  5
+    :application.start :dnssd
  6
+    :application.start :cowboy
  7
+    :application.start __MODULE__
8 8
   end
9 9
 
10 10
   def start(_type, _args) do
@@ -16,11 +16,11 @@ defmodule Cerebrate do
16 16
     dispatch = [
17 17
       {:'_', [{:'_', CerebrateWeb, [config]}]}
18 18
     ] 
19  
-    Erlang.cowboy.start_listener(:cerebrate_http_listener, 100,
  19
+    :cowboy.start_listener(:cerebrate_http_listener, 100,
20 20
       :cowboy_tcp_transport, [{:port, config[:web_port]}],
21 21
       :cowboy_http_protocol, [{:dispatch, dispatch}]
22 22
     )
23  
-    Erlang.cowboy.start_listener(:cerebrate_rpc_listener, 100,
  23
+    :cowboy.start_listener(:cerebrate_rpc_listener, 100,
24 24
       :cowboy_tcp_transport, [{:port, config[:rpc_port]}],
25 25
       CerebrateRpcProtocol, []
26 26
     )
@@ -37,9 +37,9 @@ defmodule Cerebrate do
37 37
       match: {key, nil}
38 38
         default_val
39 39
       match: {:rpc_port, val}
40  
-        Erlang.erlang.list_to_integer(binary_to_list(val))
  40
+        :erlang.list_to_integer(binary_to_list(val))
41 41
       match: {:web_port, val}
42  
-        Erlang.erlang.list_to_integer(binary_to_list(val))
  42
+        :erlang.list_to_integer(binary_to_list(val))
43 43
       match: {key, val}
44 44
         val
45 45
       end
@@ -57,7 +57,7 @@ defmodule CerebrateSupervisor do
57 57
   @behavior :supervisor
58 58
 
59 59
   def start_link(config) do
60  
-    Erlang.supervisor.start_link {:local, :cerebrate_sup}, __MODULE__, [config]
  60
+    :supervisor.start_link {:local, :cerebrate_sup}, __MODULE__, [config]
61 61
   end
62 62
 
63 63
   def init([config]) do
8  src/cerebrate_checks.ex
@@ -8,7 +8,7 @@ defmodule CerebrateChecks do
8 8
     ExLog.info "Starting Cerebrate checks"
9 9
     run {
10 10
       Port.open({:spawn, binary_to_list("python -u python/agent_port.py")}, [{:packet, 1}, :binary, :use_stdio]),
11  
-      Erlang.ets.new(:check_data, [:set, :public, :named_table])
  11
+      :ets.new(:check_data, [:set, :public, :named_table])
12 12
     }
13 13
   end
14 14
 
@@ -19,8 +19,8 @@ defmodule CerebrateChecks do
19 19
     match: data
20 20
       data
21 21
     end
22  
-    Erlang.ets.insert table, update_ets(agent_data, [])
23  
-    ok = Erlang.timer.sleep 2000
  22
+    :ets.insert table, update_ets(agent_data, [])
  23
+    ok = :timer.sleep 2000
24 24
     run state
25 25
   end
26 26
 
@@ -45,7 +45,7 @@ defmodule CerebrateChecks do
45 45
   end
46 46
 
47 47
   def get_all() do
48  
-    Erlang.ets.tab2list :check_data
  48
+    :ets.tab2list :check_data
49 49
   end
50 50
 
51 51
 end
20  src/cerebrate_rpc.ex
@@ -4,7 +4,7 @@ defmodule CerebrateRpc do
4 4
 
5 5
   def start_link(config) do
6 6
     rpc_port = config[:rpc_port]
7  
-    Erlang.dnssd.register "Cerebrate-#{rpc_port}", __MODULE__.__info__(:data)[:service_type], rpc_port
  7
+    :dnssd.register "Cerebrate-#{rpc_port}", __MODULE__.__info__(:data)[:service_type], rpc_port
8 8
     receive do
9 9
     match: {:dnssd, ref, {:register, :add, result}} 
10 10
       ExLog.info "Registered #{inspect(result)}"
@@ -20,33 +20,33 @@ defmodule CerebrateRpc do
20 20
   """
21 21
   def query_peers(command) do
22 22
     ExLog.info "querying peers for #{command}"
23  
-    Erlang.dnssd.browse(__MODULE__.__info__(:data)[:service_type])
24  
-    query_peers command, [], Erlang.sets.new(), Erlang.dict.new()
  23
+    :dnssd.browse(__MODULE__.__info__(:data)[:service_type])
  24
+    query_peers command, [], :sets.new(), :dict.new()
25 25
   end
26 26
 
27 27
   defp query_peers(command, data, seen_already, conn_lookup) do
28 28
     receive do
29 29
     match: {:dnssd, _ref, {:browse, :add, response={name, type, domain}}}
30 30
       # Found a peer, now get the port that it's listening on
31  
-      Erlang.dnssd.resolve name, type, domain
  31
+      :dnssd.resolve name, type, domain
32 32
       query_peers command, data, seen_already, conn_lookup
33 33
     match: {:dnssd, _ref, {:resolve, response={domain_dot, port, _dns_data}}}
34 34
       # Resolved the port of a peer, now connect to it and send the query
35 35
       domain = binary_to_list(Regex.replace(%r/\.$/, domain_dot, ""))
36 36
       conn = {domain, port}
37  
-      case Erlang.sets.is_element(conn, seen_already) do
  37
+      case :sets.is_element(conn, seen_already) do
38 38
       match: :true
39 39
         ExLog.info "Skipping #{inspect(conn)}"
40 40
         query_peers command, data, seen_already, conn_lookup
41 41
       match: :false
42 42
         ExLog.info "Connecting to #{inspect(conn)}"
43  
-        {:ok, socket} = Erlang.gen_tcp.connect domain, port, [:binary, {:active, :true}]      
44  
-        Erlang.gen_tcp.send socket, command
45  
-        query_peers command, data, Erlang.sets.add_element(conn, seen_already), Erlang.dict.store(socket, conn, conn_lookup)
  43
+        {:ok, socket} = :gen_tcp.connect domain, port, [:binary, {:active, :true}]      
  44
+        :gen_tcp.send socket, command
  45
+        query_peers command, data, :sets.add_element(conn, seen_already), :dict.store(socket, conn, conn_lookup)
46 46
       end
47 47
     match: {:tcp, socket, new_data}
48 48
       # Received new data from a peer, append it to the list
49  
-      {domain, port} = Erlang.dict.fetch(socket, conn_lookup)
  49
+      {domain, port} = :dict.fetch(socket, conn_lookup)
50 50
       query_peers command, [
51 51
         {list_to_binary(domain), 
52 52
          list_to_binary(integer_to_list(port)), 
@@ -79,7 +79,7 @@ defmodule CerebrateRpcProtocol do
79 79
   end
80 80
 
81 81
   def run(listener_pid, socket, transport, opts) do
82  
-    :ok = Erlang.cowboy.accept_ack(listener_pid)
  82
+    :ok = :cowboy.accept_ack(listener_pid)
83 83
     timeout = 10000
84 84
     case transport.recv(socket, 0, timeout) do
85 85
     match: {:ok, data}
8  src/cerebrate_web.ex
@@ -2,15 +2,15 @@ defmodule CerebrateWeb do
2 2
   @behavior :cowboy_http_handler
3 3
 
4 4
   def init({_, :http}, req, [_config]) do
5  
-    filename = binary_to_list(Erlang.filename.absname("priv/index.html.dtl"))
6  
-    options = [{:out_dir, Erlang.filename.absname("ebin")}]
7  
-    Erlang.erlydtl.compile filename, :cerebrate_web_index, options
  5
+    filename = binary_to_list(:filename.absname("priv/index.html.dtl"))
  6
+    options = [{:out_dir, :filename.absname("ebin")}]
  7
+    :erlydtl.compile filename, :cerebrate_web_index, options
8 8
     {:ok, req, :undefined}
9 9
   end
10 10
 
11 11
   def handle(req, state) do
12 12
     {:ok, reply} = :cerebrate_web_index.render [{:data, CerebrateRpc.check_data}]
13  
-    {:ok, req2} = Erlang.cowboy_http_req.reply(200, [], reply, req)
  13
+    {:ok, req2} = :cowboy_http_req.reply(200, [], reply, req)
14 14
     {:ok, req2, state}
15 15
   end
16 16
 
12  src/exlog.ex
@@ -2,7 +2,7 @@ defmodule ExLog do
2 2
 	use GenServer.Behavior
3 3
 
4 4
 	def start_link(config) do
5  
-		Erlang.gen_server.start_link {:local, :exlog}, __MODULE__, config, []
  5
+		:gen_server.start_link {:local, :exlog}, __MODULE__, config, []
6 6
 	end
7 7
 
8 8
 	def init(args) do
@@ -49,7 +49,7 @@ defmodule ExLog do
49 49
 
50 50
 	def date() do
51 51
 		{{year, month, day}, 
52  
-		 {hour, minute, second}} = Erlang.calendar.now_to_universal_time(:erlang.now())
  52
+		 {hour, minute, second}} = :calendar.now_to_universal_time(:erlang.now())
53 53
 		"#{year}-#{month}-#{day} #{hour}:#{minute}:#{second}"
54 54
 	end
55 55
 
@@ -64,19 +64,19 @@ defmodule ExLog do
64 64
 	end
65 65
 
66 66
 	def debug(message) do
67  
-		Erlang.gen_server.cast :exlog, {:debug, {Process.self(), message}}
  67
+		:gen_server.cast :exlog, {:debug, {Process.self(), message}}
68 68
 	end
69 69
 
70 70
 	def info(message) do
71  
-		Erlang.gen_server.cast :exlog, {:info, {Process.self(), message}}
  71
+		:gen_server.cast :exlog, {:info, {Process.self(), message}}
72 72
 	end
73 73
 	
74 74
 	def warn(message) do
75  
-		Erlang.gen_server.cast :exlog, {:warn, {Process.self(), message}}
  75
+		:gen_server.cast :exlog, {:warn, {Process.self(), message}}
76 76
 	end
77 77
 	
78 78
 	def error(message) do
79  
-		Erlang.gen_server.cast :exlog, {:error, {Process.self(), message}}
  79
+		:gen_server.cast :exlog, {:error, {Process.self(), message}}
80 80
 	end
81 81
 
82 82
 end

0 notes on commit d4adc44

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