]> gitweb.michael.orlitzky.com - list-remote-forwards.git/blob - src/MxList.hs
src/MxList.hs: use an explicit export list.
[list-remote-forwards.git] / src / MxList.hs
1 {-# LANGUAGE DeriveDataTypeable #-}
2
3 -- | A newtype around a list of Strings which represent the MXes whose
4 -- remote forwards we don't report. This is all to avoid an orphan
5 -- instance of Configured for [String] if we had defined one in
6 -- e.g. 'OptionalConfiguration'.
7 --
8 module MxList (
9 MxList(..) )
10 where
11
12 -- DC is needed only for the DCT.Configured instance of String.
13 import qualified Data.Configurator as DC()
14 import qualified Data.Configurator.Types as DCT (
15 Configured,
16 Value( List ),
17 convert )
18 import Data.Data (Data)
19 import System.Console.CmdArgs.Default (Default(..))
20 import Data.Typeable (Typeable)
21
22
23 -- | A (wrapper around a) list of MX hostnames.
24 --
25 newtype MxList =
26 MxList { get_mxs :: [String] }
27 deriving (Data, Show, Typeable)
28
29
30 -- | The default (empty) list of MXes.
31 --
32 instance Default MxList where
33 def = MxList []
34
35
36 instance DCT.Configured MxList where
37 -- | This allows us to read a MxList object out of a Configurator
38 -- config file. By default Configurator wouldn't know what to do,
39 -- so we have to tell it that we expect a list, and if that list
40 -- has strings in it, we can apply the MxList constructor to
41 -- it.
42 convert (DCT.List xs) =
43 -- mapM gives us a Maybe [String] here.
44 fmap MxList (mapM convert_string xs)
45 where
46 convert_string :: DCT.Value -> Maybe String
47 convert_string = DCT.convert
48
49 -- If we read anything other than a list of values out of the file,
50 -- fail.
51 convert _ = Nothing