plugins-auto 0.0.1 → 0.0.2
raw patch · 4 files changed
+37/−10 lines, 4 filesdep +directorydep +processdep ~base
Dependencies added: directory, process
Dependency ranges changed: base
Files
- System/Plugins/Auto.hs +21/−2
- System/Plugins/Auto/LiftName.hs +2/−1
- System/Plugins/Auto/Reloader.hs +5/−1
- plugins-auto.cabal +9/−6
System/Plugins/Auto.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE FlexibleContexts, TemplateHaskell #-}+{-# LANGUAGE TemplateHaskell #-} -- | This module implements the public interface of plugins-auto -- Create a plugin handle with 'initPlugins' and use it later with 'withMonadIO'. module System.Plugins.Auto@@ -9,13 +9,14 @@ , defaultPluginConf , withMonadIO , withMonadIO_+ , withMonadIOFile ) where import Control.Monad.Trans (MonadIO(liftIO)) import Language.Haskell.TH (ExpQ, appE, varE) import Language.Haskell.TH.Syntax (Name) import System.Plugins.Auto.LiftName (liftName)-import System.Plugins.Auto.Reloader ( PluginHandle, funcTH, initPlugins, initPluginsWithConf+import System.Plugins.Auto.Reloader ( PluginHandle, func, funcTH, initPlugins, initPluginsWithConf , defaultPluginConf, getPluginConf, PluginConf(..)) @@ -47,6 +48,24 @@ -> m b withMonadIO_ name _ ph fconf notloaded use = do (errs,ma) <- liftIO $ funcTH ph name$ getPluginConf ph fconf+ maybe (notloaded errs) (use errs) ma+++-- | Dynamically load the specified symbol from a specific .hs file+--+withMonadIOFile :: (MonadIO m) => + FilePath -- ^ path to file to load symbol from+ -> String -- ^ name of the symbol to dynamically load+ -> PluginHandle -- ^ Handle to the function reloader+ -> (PluginConf -> PluginConf) -- ^ introduces variations on the plugin configuration+ -> ([String] -> m b) -- ^ function called if the symbol is not loaded ( either because the+ -- last recompilation attempt failed or because it is being + -- compiled right now by another thread).+ -> ([String] -> a -> m b) -- ^ function which uses the loaded result, receives also a + -- list of errors in the last recompilation attempt+ -> m b+withMonadIOFile fp sym ph fconf notloaded use = do+ (errs,ma) <- liftIO $ func ph fp sym $ getPluginConf ph fconf maybe (notloaded errs) (use errs) ma
System/Plugins/Auto/LiftName.hs view
@@ -1,11 +1,12 @@ {-# LANGUAGE TemplateHaskell, MagicHash #-}-module System.Plugins.Auto.LiftName where+module System.Plugins.Auto.LiftName(liftName) where import GHC.Exts import Language.Haskell.TH import Language.Haskell.TH.Syntax import Language.Haskell.TH.Syntax.Internals +-- | Lifts a Name to an ExpQ. @$(liftName n) == n@ liftName :: Name -> ExpQ liftName (Name occName nameFlavour) = appE (appE [| Name |] (liftOccName occName)) (liftNameFlavour nameFlavour)
System/Plugins/Auto/Reloader.hs view
@@ -2,6 +2,7 @@ -- | This module implements recompilation and reloading of symbols. module System.Plugins.Auto.Reloader ( funcTH+ , func , PluginHandle , PluginConf(..) , initPlugins@@ -143,7 +144,10 @@ in (fp, sym) nameToFileSym n = error $ "nameToFileSym failed because Name was not the right kind. " ++ show n -func :: PluginHandle -> FilePath -> Symbol -> PluginConf -> IO (Errors,Maybe a)++-- | Like 'funcTH' but instead of a Name it takes the source file and +-- the contained symbol to load.+func :: PluginHandle -> FilePath -> Symbol -> PluginConf -> IO ([String],Maybe a) func ph fp sym conf = do om <- readMVar$ phObjMap ph case Map.lookup fp om of
plugins-auto.cabal view
@@ -1,5 +1,5 @@ Name: plugins-auto-Version: 0.0.1+Version: 0.0.2 Synopsis: Automatic recompilation and reloading of haskell modules. Description: This library provides support for automatically recompiling and reloading modules into your programs when the source code is modified. @@ -44,15 +44,12 @@ Maintainer: Happstack team <happs@googlegroups.com> Category: System Build-Type: Simple-Cabal-Version: >= 1.6+Cabal-Version: >= 1.8 source-repository head type: darcs location: http://patch-tag.com/r/facundo/plugins-auto--Flag tests- Description: Build the testsuite, and include the tests in the library- Default: False+ tag: 0.0.2 Library exposed-modules: System.Plugins.Auto@@ -69,3 +66,9 @@ template-haskell ghc-options: -Wall++Test-Suite test-plugins-auto+ type: exitcode-stdio-1.0+ main-is: Test/Test.hs+ build-depends: base, directory, process+