I have a package where some functionality should always be loaded when 
writing the normal "using MyPackage" and some functionality needs to be 
explicitly loaded. The use case for me is that I have a library of 
different things (let's call them books) and it is likely that only a few 
books from this library are used and I want to reduce the loading time of 
the package.

To make it concrete let's assume I currently have the following file/module 
structure:
# MyPackage.jl
module MyPackage
export foo
include("required.jl")
include("library.jl")
end

# required.jl
abstract AbstractBook
foo(a::AbstractBook) = print(a)

# library.jl

include("book1.jl")
include("book2.jl")

# book1.jl
type Book1 <: AbstractBook

# book2.jl (oh boy...)
using Gadfly
using Winston
using Images
using PyCall
type Book2 <: AbstractBook

Now, I want my usage of the package to look something like this:
using MyPackage # Loads everything required
using MyPackage.Library.Book1 # Only loads book1.jl, book2.jl is not 
touched, fast loading

Foo(Book1())

I guess I have to put my books into their own separate modules, akin:

# MyPackage.jl
module MyPackage
export foo
include("required.jl")
end

# required.jl
abstract AbstractBook
foo(a::AbstractBook) = print(a)

# book1.jl
module BookModule1
using MyPackage
export Book1
type Book1 <: AbstractBook
end

# book2.jl
module BookModule2
using MyPackage
export Book2
type Book2 <: AbstractBook
end

But now there is no convenient way to load the book modules?

Can anyone help me how to properly structure this? A link to a package that 
does this will likely work just fine.

Best regards,
Kristoffer Carlsson

Reply via email to