Move ActionConfig and some other types to Types.hs
Move ActionConfig and some other types to Types.hs
diff --git a/Blog/Blog b/Blog/Blog
index 0da370e..3bd8293 100755
Binary files a/Blog/Blog and b/Blog/Blog differ
diff --git a/Framework/API.hs b/Framework/API.hs
index 438edc9..fea71ca 100644
--- a/Framework/API.hs
+++ b/Framework/API.hs
@@ -30,18 +30,6 @@ import Framework.Models (Model)
import Framework.Http.Response ((<+>))
import Framework.Http.HTTPServer (serveHttp,serveStatic)
--- | Runtime controller action configuration
-data ActionConfig = ActionConfig {
- request :: Httpd.Request, -- ^ HTTP request
- httpParams :: StaticConfig, -- ^ Static (global) configuration
- dbconnection :: Storage.DBConnection, -- ^ DB connection
- sessionID :: Sessions.SessionID, -- ^ Current HTTP session ID
- sessionMap :: Sessions.SessionMap, -- ^ Contains session variables
- sessionsBackend :: Sessions.SessionsConnection, -- ^ Connection to sessions backend
- cacheBackend :: Cache.CacheConnection, -- ^ Connection to cache backend
- cookiesExp :: String -- ^ Cookies expiration date
- }
-
----------------------------------------------------------------------------------------------------------
-- * Sessions API
diff --git a/Framework/Cache.hs b/Framework/Cache.hs
index fafb825..0aa2b08 100644
--- a/Framework/Cache.hs
+++ b/Framework/Cache.hs
@@ -21,21 +21,12 @@ import qualified Network.Memcache.Protocol as SMC
import Network.Memcache.Serializable (Serializable(..))
import Framework.Utils
+import Framework.CacheTypes
-- $doc
-- This module manages caching of any data. Caching is implemented by several backends,
-- such as Memcache and Filesystem.
-class CacheBackend b where
- cinit :: String -> IO b -- ^ Init cache backend
- cget :: (Serializable v) => b -> String -> IO (Maybe v) -- ^ Get data from cache
- cput :: (Serializable v) => b -> String -> v -> IO Bool -- ^ Put data to cache
- cunset :: b -> String -> IO Bool -- ^ Unset data
- cfree :: b -> IO () -- ^ Free backend
-
--- | Type to incapsulate connection to any cache backend.
-data CacheConnection = forall b. (CacheBackend b) => CConnection b
-
data MemcacheBackend = MB SMC.Server
data FilesystemBackend = FB String
data FakeBackend = Fake
diff --git a/Framework/CacheTypes.hs b/Framework/CacheTypes.hs
new file mode 100644
index 0000000..5c562d0
--- /dev/null
+++ b/Framework/CacheTypes.hs
@@ -0,0 +1,15 @@
+{-# LANGUAGE ExistentialQuantification #-}
+module Framework.CacheTypes where
+
+import Network.Memcache.Serializable (Serializable(..))
+
+class CacheBackend b where
+ cinit :: String -> IO b -- ^ Init cache backend
+ cget :: (Serializable v) => b -> String -> IO (Maybe v) -- ^ Get data from cache
+ cput :: (Serializable v) => b -> String -> v -> IO Bool -- ^ Put data to cache
+ cunset :: b -> String -> IO Bool -- ^ Unset data
+ cfree :: b -> IO () -- ^ Free backend
+
+-- | Type to incapsulate connection to any cache backend.
+data CacheConnection = forall b. (CacheBackend b) => CConnection b
+
diff --git a/Framework/Http/SessionTypes.hs b/Framework/Http/SessionTypes.hs
new file mode 100644
index 0000000..1c000ef
--- /dev/null
+++ b/Framework/Http/SessionTypes.hs
@@ -0,0 +1,19 @@
+{-# LANGUAGE ExistentialQuantification #-}
+module Framework.Http.SessionTypes where
+
+import qualified Data.Map as M
+
+type SessionID = String
+type SessionMap = M.Map String String
+
+data Session = NewSession SessionID
+ | ExistingSession SessionID SessionMap
+ deriving (Show)
+
+class SessionBackend b where
+ sinit :: String -> IO b
+ sfetch :: b -> SessionID -> IO SessionMap
+ spush :: b -> SessionID -> SessionMap -> IO ()
+ sfree :: b -> IO ()
+
+data SessionsConnection = forall b. (SessionBackend b) => SConnection b
diff --git a/Framework/Http/Sessions.hs b/Framework/Http/Sessions.hs
index 26fd6b7..fe90b29 100644
--- a/Framework/Http/Sessions.hs
+++ b/Framework/Http/Sessions.hs
@@ -23,21 +23,7 @@ import Network.Shed.Httpd(Request)
import Framework.Types
import Framework.Utils
import Framework.Http.Cookies
-
-type SessionID = String
-type SessionMap = M.Map String String
-
-data Session = NewSession SessionID
- | ExistingSession SessionID SessionMap
- deriving (Show)
-
-class SessionBackend b where
- sinit :: String -> IO b
- sfetch :: b -> SessionID -> IO SessionMap
- spush :: b -> SessionID -> SessionMap -> IO ()
- sfree :: b -> IO ()
-
-data SessionsConnection = forall b. (SessionBackend b) => SConnection b
+import Framework.Http.SessionTypes
data FilesBackend = FB String
diff --git a/Framework/Storage.hs b/Framework/Storage.hs
index fd8fbe2..92b4583 100644
--- a/Framework/Storage.hs
+++ b/Framework/Storage.hs
@@ -18,9 +18,6 @@ import qualified Database.HDBC as D
import Framework.Types
import Framework.Models
--- | Container type for any database connection
-data DBConnection = forall c. D.IConnection c => DBC c
-
-- | Connect to DB
connect :: String -- ^ DB backend
-> String -- ^ DB connection path (format is backend-specific)
diff --git a/Framework/Types.hs b/Framework/Types.hs
index 3ff4d52..0192d92 100644
--- a/Framework/Types.hs
+++ b/Framework/Types.hs
@@ -7,12 +7,18 @@ import Data.List
import qualified Data.Map as M
import qualified Database.HDBC as D
+import Framework.Http.SessionTypes
+import Framework.CacheTypes
+
----------------------------------------------------------------
--Types
--
type Channel = Handle
type S = String
+-- | Container type for any database connection
+data DBConnection = forall c. D.IConnection c => DBC c
+
-------------------------------------------------------------------------------------------
data StaticConfig = HP {
@@ -27,6 +33,18 @@ data StaticConfig = HP {
}
deriving (Show)
+-- | Runtime controller action configuration
+data ActionConfig = ActionConfig {
+ request :: Request, -- ^ HTTP request
+ httpParams :: StaticConfig, -- ^ Static (global) configuration
+ dbconnection :: DBConnection, -- ^ DB connection
+ sessionID :: SessionID, -- ^ Current HTTP session ID
+ sessionMap :: SessionMap, -- ^ Contains session variables
+ sessionsBackend :: SessionsConnection, -- ^ Connection to sessions backend
+ cacheBackend :: CacheConnection, -- ^ Connection to cache backend
+ cookiesExp :: String -- ^ Cookies expiration date
+ }
+
class HttpValue v where
httpEmpty :: v -> Bool
httpShow :: v -> String