Packages
Typed distributed messaging for Gleam on the BEAM.
Retired package: Deprecated - The project needs to be redesigned around a much smaller and clearer core.
Current section
Files
Jump to
Current section
Files
src/test_helpers_ffi.erl
%% Test helper FFI for Gleam tests
-module(test_helpers_ffi).
-export([binary_to_existing_atom_exists/1, get_allow_atom_creation/0, inspect_to_atom/1, inspect_to_atom_status/1]).
binary_to_existing_atom_exists(Bin) when is_binary(Bin) ->
case catch binary_to_existing_atom(Bin, utf8) of
{'EXIT', _} -> false;
_Atom -> true
end;
binary_to_existing_atom_exists(_) -> false.
get_allow_atom_creation() -> persistent_term:get(distribute_allow_atom_creation, false).
inspect_to_atom(Bin) when is_binary(Bin) ->
case catch binary_to_existing_atom(Bin, utf8) of
{'EXIT', _} -> case persistent_term:get(distribute_allow_atom_creation, false) of
true -> {ok, {created, binary_to_atom(Bin, utf8)}};
false -> {error, atom_not_existing}
end;
Atom -> {ok, {existing, Atom}}
end;
inspect_to_atom(List) when is_list(List) -> inspect_to_atom(list_to_binary(List));
inspect_to_atom(Atom) when is_atom(Atom) -> {ok, {existing, Atom}};
inspect_to_atom(_) -> {error, badarg}.
inspect_to_atom_status(Bin) when is_binary(Bin) ->
Allow = persistent_term:get(distribute_allow_atom_creation, false),
case catch binary_to_existing_atom(Bin, utf8) of
{'EXIT', _} -> case Allow of
true -> <<"created">>;
false -> <<"error">>
end;
_Atom -> <<"existing">>
end;
inspect_to_atom_status(List) when is_list(List) -> inspect_to_atom_status(list_to_binary(List));
inspect_to_atom_status(Atom) when is_atom(Atom) -> <<"existing">>;
inspect_to_atom_status(_) -> <<"error">>.