packages feed

boots 0.0.2 → 0.0.3

raw patch · 9 files changed

+51/−68 lines, 9 filesdep −bootsdep ~salakdep ~salak-yamlPVP ok

version bump matches the API change (PVP)

Dependencies removed: boots

Dependency ranges changed: salak, salak-yaml

API changes (from Hackage documentation)

+ Boots: combine :: [Plugin i m i] -> Plugin i m i
+ Boots: wrapP :: ((u -> m ()) -> m ()) -> Plugin i m u
+ Boots.Plugin: boot :: Monad m => Plugin () m (m ()) -> m ()
+ Boots.Plugin: bracketP :: forall m i u. MonadCatch m => m u -> (u -> m ()) -> Plugin i m u
+ Boots.Plugin: combine :: [Plugin i m i] -> Plugin i m i
+ Boots.Plugin: data Plugin i m u
+ Boots.Plugin: isoPlugin :: (m () -> n ()) -> (n () -> m ()) -> Plugin i n u -> Plugin i m u
+ Boots.Plugin: mapPlugin :: (m () -> m ()) -> Plugin i m u -> Plugin i m u
+ Boots.Plugin: promote :: i -> Plugin i m u -> Plugin x m u
+ Boots.Plugin: runPlugin :: i -> Plugin i m u -> (u -> m ()) -> m ()
+ Boots.Plugin: withPlugin :: (i -> j) -> Plugin j m u -> Plugin i m u
+ Boots.Plugin: wrapP :: ((u -> m ()) -> m ()) -> Plugin i m u
+ Boots.Plugin.Logger: instance (Control.Monad.IO.Class.MonadIO m, Boots.Plugin.Logger.HasLogger cxt) => Control.Monad.Logger.MonadLoggerIO (Boots.Internal.App.AppT cxt m)
+ Boots.Plugin.Logger: instance (Control.Monad.IO.Class.MonadIO m, Boots.Plugin.Logger.HasLogger cxt) => Control.Monad.Logger.MonadLoggerIO (Boots.Internal.Plugin.Plugin cxt m)

Files

README.md view
@@ -1,9 +1,10 @@ # boots -[![Hackage](https://img.shields.io/hackage/v/boots.svg)](https://hackage.haskell.org/package/boots)+[![Hackage](https://img.shields.io/hackage/v/boots.svg?logo=haskell)](https://hackage.haskell.org/package/boots)+[![Build](https://img.shields.io/travis/leptonyu/boots.svg?logo=travis)](https://travis-ci.org/leptonyu/boots) [![stackage LTS package](http://stackage.org/package/boots/badge/lts)](http://stackage.org/lts/package/boots) [![stackage Nightly package](http://stackage.org/package/boots/badge/nightly)](http://stackage.org/nightly/package/boots)-[![Build Status](https://travis-ci.org/leptonyu/boots.svg?branch=master)](https://travis-ci.org/leptonyu/boots)+[![MIT license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/leptonyu/boots/blob/master/LICENSE)  Boot applications by using plugins. @@ -13,7 +14,12 @@  When we decide to create an application using Haskell. We may need using configurations, loggers as basic functions. If this application needs storages, caches, etc., then we have to weaving the management of connection of these facilities into the application. Connections need to be created before and be destroyed after using them. There is a common strategy to manage connections, that is using `Control.Monad.Cont`. Then we can encapsulate the management of connections separately. For example, we can write a database plugin `Plugin cxt m DBConnection`, which can manage the database connections in monad `m` with context `cxt`. Context `cxt` may be requested for configurations or logging functions. When all the components of application are encapsulated by plugins, then building an application will be simplified. +## A Project Use boots to Build++Refer to [鬼谷子](https://github.com/leptonyu/guiguzi)+ ### Have a Try+  ```Haskell main :: IO ()
boots.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.12 name: boots-version: 0.0.2+version: 0.0.3 license: MIT license-file: LICENSE copyright: 2019 Daniel YU@@ -33,29 +33,6 @@                         FlexibleContexts RankNTypes ScopedTypeVariables     build-depends:         base >=4.10 && <5,-        data-default >=0.7.1.1 && <0.8,-        exceptions >=0.10.2 && <0.11,-        fast-logger >=2.4.16 && <2.5,-        microlens >=0.4.10 && <0.5,-        monad-logger >=0.3.30 && <0.4,-        mtl >=2.2.2 && <2.3,-        salak >=0.3.1 && <0.4,-        salak-yaml >=0.3.1 && <0.4,-        text >=1.2.3.1 && <1.3,-        unliftio-core >=0.1.2.0 && <0.2--executable boots-exe-    main-is: Main.hs-    hs-source-dirs: main-    other-modules:-        Paths_boots-    default-language: Haskell2010-    default-extensions: FlexibleInstances MultiParamTypeClasses-                        GeneralizedNewtypeDeriving OverloadedStrings RecordWildCards-                        FlexibleContexts RankNTypes ScopedTypeVariables-    build-depends:-        base >=4.10 && <5,-        boots -any,         data-default >=0.7.1.1 && <0.8,         exceptions >=0.10.2 && <0.11,         fast-logger >=2.4.16 && <2.5,
− main/Main.hs
@@ -1,12 +0,0 @@-module Main where--import           Boots-import           Control.Concurrent-import           Control.Monad--main :: IO ()-main = bootApp (pluginSimple "application") go-  where-    go = forever $ do-      logInfo "Hello, world!"-      liftIO $ threadDelay 1000000
src/Boots.hs view
@@ -13,15 +13,15 @@ -- Simplify to create an application in Haskell. -- -- When we decide to create an application using Haskell.--- We may need using configurations, loggers as basic functions. --- If this application needs storages, caches, etc., --- then we have to weaving the management of connection of these facilities into the application. --- Connections need to be created before and be destroyed after using them. --- There is a common strategy to manage connections, that is using `Control.Monad.Cont`. --- Then we can encapsulate the management of connections separately. --- For example, we can write a database plugin `Plugin` @cxt@ @m@ @DBConnection@, --- which can manage the database connections in monad @m@ with context @cxt@. --- Context @cxt@ may be requested for getting configurations or logging functions. +-- We may need using configurations, loggers as basic functions.+-- If this application needs storages, caches, etc.,+-- then we have to weaving the management of connection of these facilities into the application.+-- Connections need to be created before and be destroyed after using them.+-- There is a common strategy to manage connections, that is using `Control.Monad.Cont`.+-- Then we can encapsulate the management of connections separately.+-- For example, we can write a database plugin `Plugin` @cxt@ @m@ @DBConnection@,+-- which can manage the database connections in monad @m@ with context @cxt@.+-- Context @cxt@ may be requested for getting configurations or logging functions. -- When all the components of application are encapsulated by plugins, then building an application will be simplified. -- -- * Have a Try@@ -32,7 +32,7 @@ -- 2019-07-27 19:37:45  INFO [application] Ghci2 - daniel -- -- Main--- +-- -- > main :: IO () -- > main = bootApp (pluginSimple "application") go -- >   where@@ -44,8 +44,8 @@  module Boots(     module Boots.Internal-  , module Boots.Plugin+  , module Boots.Plugin.Simple   ) where  import           Boots.Internal-import           Boots.Plugin+import           Boots.Plugin.Simple
src/Boots/Internal.hs view
@@ -6,12 +6,11 @@ -- Stability:   experimental -- Portability: portable ----- Boot cores.+-- Boot plugin and application. -- module Boots.Internal(   -- * Plugin-    boot-  , module Boots.Internal.Plugin+    module Boots.Internal.Plugin   -- * Application   , bootApp   , module Boots.Internal.App@@ -19,10 +18,6 @@  import           Boots.Internal.App import           Boots.Internal.Plugin---- | Run application only in plugin.-boot :: Monad m => Plugin () m (m ()) -> m ()-boot plugin = runPlugin () plugin id  -- | Run application in context with the help of plugin. Context @cxt@ can't escape from @m@. --  If you want to define your own `AppT` then please use 'boot' or 'runPlugin'.
src/Boots/Internal/Plugin.hs view
@@ -9,13 +9,16 @@ -- This module defines a generic application plugin used when booting application. -- module Boots.Internal.Plugin(-    Plugin+    boot+  , Plugin   , runPlugin   , promote+  , combine   , withPlugin   , mapPlugin   , isoPlugin   , bracketP+  , wrapP   ) where  import           Control.Monad.Catch@@ -30,6 +33,10 @@ runPlugin :: i -> Plugin i m u -> (u -> m ()) -> m () runPlugin i pma = runContT (runReaderT (unPlugin pma) i) +-- | Run application only in plugin.+boot :: Monad m => Plugin () m (m ()) -> m ()+boot plugin = runPlugin () plugin id+ instance MonadTrans (Plugin i) where   lift = Plugin . lift . lift @@ -45,6 +52,10 @@ promote :: i -> Plugin i m u -> Plugin x m u promote i pimu = Plugin $ lift $ ContT (runPlugin i pimu) +-- | Combines plugins into one.+combine :: [Plugin i m i] -> Plugin i m i+combine = foldl (\b a -> b >>= \i -> promote i a) ask+ -- | Convert a plugin into another. withPlugin :: (i -> j) -> Plugin j m u -> Plugin i m u withPlugin f = Plugin . withReaderT f . unPlugin@@ -58,6 +69,11 @@ -- | Apply a function to transform the result of a continuation-passing computation. mapPlugin :: (m () -> m ()) -> Plugin i m u -> Plugin i m u mapPlugin f = Plugin . mapReaderT (mapContT f) . unPlugin+++-- | Warp plugin.+wrapP :: ((u -> m ()) -> m ()) -> Plugin i m u+wrapP = Plugin . lift . ContT  -- | Create bracket style plugin, used for manage resources, which need to open and close. --
src/Boots/Plugin.hs view
@@ -6,17 +6,10 @@ -- Stability:   experimental -- Portability: portable ----- Boot plugins.+-- Boot plugin. -- module Boots.Plugin(-  -- * Simple Plugin-    module Boots.Plugin.Simple-  -- * Configuration Plugin-  , module Boots.Plugin.Salak-  -- * Logger Plugin-  , module Boots.Plugin.Logger+    module Boots.Internal.Plugin   ) where -import           Boots.Plugin.Logger-import           Boots.Plugin.Salak-import           Boots.Plugin.Simple+import           Boots.Internal.Plugin
src/Boots/Plugin/Logger.hs view
@@ -53,6 +53,12 @@     LogFunc{..} <- asks (view askLogger)     liftIO $ logfunc a b c (toLogStr d) +instance (MonadIO m, HasLogger cxt) => MonadLoggerIO (Plugin cxt m) where+  askLoggerIO = logfunc <$> asks (view askLogger)++instance (MonadIO m, HasLogger cxt) => MonadLoggerIO (AppT cxt m) where+  askLoggerIO = logfunc <$> asks (view askLogger)+ instance Monad m => FromProp m LogLevel where   fromProp = readEnum (fromEnumProp.toLower)     where
src/Boots/Plugin/Simple.hs view
@@ -12,6 +12,8 @@     Simple(..)   , HasSimple(..)   , pluginSimple+  , module Boots.Plugin.Salak+  , module Boots.Plugin.Logger   ) where  import           Boots.Internal