Skip to content

Commit

Permalink
move load/unload stuff to private functions
Browse files Browse the repository at this point in the history
* PKG_ADD, PKG_DEL: remove script body and call provate function

* private/sqlite_pkg_add.m, private/sqlite_pkg_del.m: new file
  • Loading branch information
lostbard committed Oct 10, 2022
1 parent 5c9c096 commit 8b86a28
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 28 deletions.
17 changes: 3 additions & 14 deletions inst/PKG_ADD
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
# on package load, attempt to load docs
try
pkg_dir = fileparts (fullfile (mfilename ("fullpath")));
doc_file = fullfile (pkg_dir, "doc", "octave-aqlite.qch");
if exist(doc_file, "file")
if exist("__event_manager_register_documentation__")
__event_manager_register_documentation__ (doc_file);
elseif exist("__event_manager_register_doc__")
__event_manager_register_doc__ (doc_file);
endif
endif
catch
# do nothing
end_try_catch
# on package load, call private add

sqlite_pkg_add();
16 changes: 2 additions & 14 deletions inst/PKG_DEL
Original file line number Diff line number Diff line change
@@ -1,14 +1,2 @@
# on package unload, attempt to unload docs
try
pkg_dir = fileparts (fullfile (mfilename ("fullpath")));
doc_file = fullfile (pkg_dir, "doc", "octave-sqlite.qch");
if exist(doc_file, "file")
if exist("__event_manager_unregister_documentation__")
__event_manager_unregister_documentation__ (doc_file);
elseif exist("__event_manager_unregister_doc__")
__event_manager_unregister_doc__ (doc_file);
endif
endif
catch
# do nothing
end_try_catch
# on unload, call private del
sqlite_pkg_del ();
42 changes: 42 additions & 0 deletions inst/private/sqlite_pkg_add.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
## Copyright (C) 2022 John Donoghue <john.donoghue@ieee.org>
##
## This program is free software: you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see
## <https://www.gnu.org/licenses/>.

## -*- texinfo -*-
## @deftypefn {} {} sqlite_pkg_add()
## private function
## @end deftypefn
function sqlite_pkg_add ()
# on package load, attempt to load docs
try
pkg_dir = fileparts (fullfile (mfilename ("fullpath")));
doc_file = fullfile (pkg_dir, "..", "doc", "octave-aqlite.qch");
if exist(doc_file, "file")
if exist("__event_manager_register_documentation__")
__event_manager_register_documentation__ (doc_file);
elseif exist("__event_manager_register_doc__")
__event_manager_register_doc__ (doc_file);
endif
endif
catch
# do nothing
end_try_catch

# if table type exists, use it, otherwise use dbtable
if exist ("table") == 0
assignin("base", "table", @dbtable);
endif

endfunction
45 changes: 45 additions & 0 deletions inst/private/sqlite_pkg_del.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## Copyright (C) 2022 John Donoghue <john.donoghue@ieee.org>
##
## This program is free software: you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see
## <https://www.gnu.org/licenses/>.

## -*- texinfo -*-
## @deftypefn {} {} sqlite_pkg_del()
## private function
## @end deftypefn
function sqlite_pkg_del ()

# on package unload, attempt to unload docs
try
pkg_dir = fileparts (fullfile (mfilename ("fullpath")));
doc_file = fullfile (pkg_dir, "..", "doc", "octave-sqlite.qch");
if exist(doc_file, "file")
if exist("__event_manager_unregister_documentation__")
__event_manager_unregister_documentation__ (doc_file);
elseif exist("__event_manager_unregister_doc__")
__event_manager_unregister_doc__ (doc_file);
endif
endif
catch
# do nothing
end_try_catch

try
if exist ("table") == 1 && (table == @dbtable)
evalin("base", "clear table");
endif
catch
# do nothing
end_try_catch
endfunction

0 comments on commit 8b86a28

Please sign in to comment.