Data.Configurator.Types

configurator-0.3.0.0: Configuration management

Copyright | (c) 2011 MailRank Inc.
License | BSD3
Maintainer | Bryan O'Sullivan <bos@serpentine.com>
Stability | experimental
Portability | portable
Safe Haskell | Safe
Language | Haskell98

Data.Configurator.Types

Contents

- Exceptions
- Notification of configuration changes

Description

Types for working with configuration files.

Synopsis

- data AutoConfig = AutoConfig {
  - interval :: Int
  - onError :: SomeException -> IO ()
  }
- data Config
- type Name = Text
- data Value
  - = Bool Bool
  - | String Text
  - | Number Rational
  - | List [Value]
- class Configured a where
- convert :: Configured a => Value -> Maybe a
- data Worth a
  - = Required {
    - worth :: a
    }
  - | Optional {
    - worth :: a
    }
- data ConfigError = ParseError FilePath String
- data KeyError = KeyError Name
- data Pattern
- type ChangeHandler = Name -> Maybe Value -> IO ()

# Documentation

data AutoConfig #

Directions for automatically reloading `Config` data.

Constructors

AutoConfig |
Fields interval :: Int Interval (in seconds) at which to check for updates to config files. The smallest allowed interval is one second. onError :: SomeException -> IO () Action invoked when an attempt to reload a `Config` or notify a `ChangeHandler` causes an exception to be thrown. If this action rethrows its exception or throws a new exception, the modification checking thread will be killed. You may want your application to treat that as a fatal error, as its configuration may no longer be consistent.

Instances

Show AutoConfig # |
Methods showsPrec :: Int -> AutoConfig -> ShowS # show :: AutoConfig -> String # showList :: [AutoConfig] -> ShowS #

data Config #

Configuration data.

type Name = Text #

The name of a `Config` value.

data Value #

A value in a `Config`.

Constructors

Bool Bool | A Boolean. Represented in a configuration file as `on` or `off`, `true` or `false` (case sensitive).
String Text | A Unicode string. Represented in a configuration file as text surrounded by double quotes. Escape sequences: `\n` - newline `\r` - carriage return `\t` - horizontal tab `\\` - backslash `\"` - quotes `\u`xxxx - Unicode character, encoded as four hexadecimal digits `\u`xxxx`\u`xxxx - Unicode character (as two UTF-16 surrogates)
Number Rational | Integer.
List [Value] | Heterogeneous list. Represented in a configuration file as an opening square bracket "`[`", followed by a comma-separated series of values, ending with a closing square bracket "`]`".

Instances

Eq Value # |
Methods (==) :: Value -> Value -> Bool # (/=) :: Value -> Value -> Bool #
Data Value # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Value -> c Value # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Value # toConstr :: Value -> Constr # dataTypeOf :: Value -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c Value) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Value) # gmapT :: (forall b. Data b => b -> b) -> Value -> Value # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Value -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Value -> r # gmapQ :: (forall d. Data d => d -> u) -> Value -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Value -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Value -> m Value # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Value -> m Value # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Value -> m Value #
Show Value # |
Methods showsPrec :: Int -> Value -> ShowS # show :: Value -> String # showList :: [Value] -> ShowS #

class Configured a where #

This class represents types that can be automatically and safely converted from a `Value` to a destination type. If conversion fails because the types are not compatible, `Nothing` is returned.

For an example of compatibility, a `Value` of `Bool` `True` cannot be `convert`ed to an `Int`.

Minimal complete definition

convert

Methods

convert :: Value -> Maybe a #

Instances

Configured a => Configured [a] # |
Methods convert :: Value -> Maybe [a] # convertList :: Value -> Maybe [[a]]

convert :: Configured a => Value -> Maybe a #

data Worth a #

Constructors

Required |
Fields worth :: a
Optional |
Fields worth :: a

Instances

Functor Worth # |
Methods fmap :: (a -> b) -> Worth a -> Worth b # (<$) :: a -> Worth b -> Worth a #
Eq a => Eq (Worth a) # |
Methods (==) :: Worth a -> Worth a -> Bool # (/=) :: Worth a -> Worth a -> Bool #
Show a => Show (Worth a) # |
Methods showsPrec :: Int -> Worth a -> ShowS # show :: Worth a -> String # showList :: [Worth a] -> ShowS #
IsString (Worth FilePath) # |
Methods fromString :: String -> Worth FilePath #
Hashable a => Hashable (Worth a) # |
Methods hashWithSalt :: Int -> Worth a -> Int # hash :: Worth a -> Int #

# Exceptions

data ConfigError #

An error occurred while processing a configuration file.

Constructors

ParseError FilePath String |

Instances

Show ConfigError # |
Methods showsPrec :: Int -> ConfigError -> ShowS # show :: ConfigError -> String # showList :: [ConfigError] -> ShowS #
Exception ConfigError # |
Methods toException :: ConfigError -> SomeException # fromException :: SomeException -> Maybe ConfigError # displayException :: ConfigError -> String #

data KeyError #

An error occurred while lookup up the given `Name`.

Constructors

KeyError Name |

Instances

Show KeyError # |
Methods showsPrec :: Int -> KeyError -> ShowS # show :: KeyError -> String # showList :: [KeyError] -> ShowS #
Exception KeyError # |
Methods toException :: KeyError -> SomeException # fromException :: SomeException -> Maybe KeyError # displayException :: KeyError -> String #

# Notification of configuration changes

data Pattern #

A pattern specifying the name of a property that has changed.

This type is an instance of the `IsString` class. If you use the `OverloadedStrings` language extension and want to write a `prefix`-matching pattern as a literal string, do so by suffixing it with "`.*`", for example as follows:

    "foo.*"

If a pattern written as a literal string does not end with "`.*`", it is assumed to be `exact`.

Instances

Eq Pattern # |
Methods (==) :: Pattern -> Pattern -> Bool # (/=) :: Pattern -> Pattern -> Bool #
Data Pattern # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Pattern -> c Pattern # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Pattern # toConstr :: Pattern -> Constr # dataTypeOf :: Pattern -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c Pattern) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Pattern) # gmapT :: (forall b. Data b => b -> b) -> Pattern -> Pattern # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Pattern -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Pattern -> r # gmapQ :: (forall d. Data d => d -> u) -> Pattern -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Pattern -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Pattern -> m Pattern # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Pattern -> m Pattern # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Pattern -> m Pattern #
Show Pattern # |
Methods showsPrec :: Int -> Pattern -> ShowS # show :: Pattern -> String # showList :: [Pattern] -> ShowS #
IsString Pattern # |
Methods fromString :: String -> Pattern #
Hashable Pattern # |
Methods hashWithSalt :: Int -> Pattern -> Int # hash :: Pattern -> Int #

type ChangeHandler #

Arguments

= Name | Name of the changed property.
-> Maybe Value | Its new value, or `Nothing` if it has vanished.
-> IO () |

An action to be invoked if a configuration property is changed.

If this action is invoked and throws an exception, the `onError` function will be called.