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-Inferred
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
- 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 Source #

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

Instances details

Show AutoConfig Source # |
Instance details Defined in Data.Configurator.Types.Internal Methods showsPrec :: Int -> AutoConfig -> ShowS Source # show :: AutoConfig -> String Source # showList :: [AutoConfig] -> ShowS Source #

data Config Source #

Configuration data.

type Name = Text Source #

The name of a `Config` value.

data Value Source #

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

Instances details

Configured Value Source # |
Instance details Defined in Data.Configurator.Instances Methods convert :: Value -> Maybe Value Source # convertList :: Value -> Maybe [Value]
Data Value Source # |

Instance details

Defined in Data.Configurator.Types.Internal

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Value -> c Value Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Value Source #

toConstr :: Value -> Constr Source #

dataTypeOf :: Value -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Value) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Value) Source #

gmapT :: (forall b. Data b => b -> b) -> Value -> Value Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Value -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Value -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Value -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Value -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Value -> m Value Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Value -> m Value Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Value -> m Value Source #

Show Value Source # |
Instance details Defined in Data.Configurator.Types.Internal Methods showsPrec :: Int -> Value -> ShowS Source # show :: Value -> String Source # showList :: [Value] -> ShowS Source #
Eq Value Source # |
Instance details Defined in Data.Configurator.Types.Internal Methods (==) :: Value -> Value -> Bool Source # (/=) :: Value -> Value -> Bool Source #

class Configured a Source #

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

#### Instances

Instances details

Configured ByteString Source # |
Instance details Defined in Data.Configurator.Instances Methods convert :: Value -> Maybe ByteString Source # convertList :: Value -> Maybe [ByteString]
Configured ByteString Source # |
Instance details Defined in Data.Configurator.Instances Methods convert :: Value -> Maybe ByteString Source # convertList :: Value -> Maybe [ByteString]
Configured Value Source # |
Instance details Defined in Data.Configurator.Instances Methods convert :: Value -> Maybe Value Source # convertList :: Value -> Maybe [Value]
Configured CDouble Source # |
Instance details Defined in Data.Configurator.Instances Methods convert :: Value -> Maybe CDouble Source # convertList :: Value -> Maybe [CDouble]
Configured CFloat Source # |
Instance details Defined in Data.Configurator.Instances Methods convert :: Value -> Maybe CFloat Source # convertList :: Value -> Maybe [CFloat]
Configured Int16 Source # |
Instance details Defined in Data.Configurator.Instances Methods convert :: Value -> Maybe Int16 Source # convertList :: Value -> Maybe [Int16]
Configured Int32 Source # |
Instance details Defined in Data.Configurator.Instances Methods convert :: Value -> Maybe Int32 Source # convertList :: Value -> Maybe [Int32]
Configured Int64 Source # |
Instance details Defined in Data.Configurator.Instances Methods convert :: Value -> Maybe Int64 Source # convertList :: Value -> Maybe [Int64]
Configured Int8 Source # |
Instance details Defined in Data.Configurator.Instances Methods convert :: Value -> Maybe Int8 Source # convertList :: Value -> Maybe [Int8]
Configured Word16 Source # |
Instance details Defined in Data.Configurator.Instances Methods convert :: Value -> Maybe Word16 Source # convertList :: Value -> Maybe [Word16]
Configured Word32 Source # |
Instance details Defined in Data.Configurator.Instances Methods convert :: Value -> Maybe Word32 Source # convertList :: Value -> Maybe [Word32]
Configured Word64 Source # |
Instance details Defined in Data.Configurator.Instances Methods convert :: Value -> Maybe Word64 Source # convertList :: Value -> Maybe [Word64]
Configured Word8 Source # |
Instance details Defined in Data.Configurator.Instances Methods convert :: Value -> Maybe Word8 Source # convertList :: Value -> Maybe [Word8]
Configured Text Source # |
Instance details Defined in Data.Configurator.Instances Methods convert :: Value -> Maybe Text Source # convertList :: Value -> Maybe [Text]
Configured Text Source # |
Instance details Defined in Data.Configurator.Instances Methods convert :: Value -> Maybe Text Source # convertList :: Value -> Maybe [Text]
Configured Integer Source # |
Instance details Defined in Data.Configurator.Instances Methods convert :: Value -> Maybe Integer Source # convertList :: Value -> Maybe [Integer]
Configured Bool Source # |
Instance details Defined in Data.Configurator.Instances Methods convert :: Value -> Maybe Bool Source # convertList :: Value -> Maybe [Bool]
Configured Char Source # |
Instance details Defined in Data.Configurator.Instances Methods convert :: Value -> Maybe Char Source # convertList :: Value -> Maybe [Char]
Configured Double Source # |
Instance details Defined in Data.Configurator.Instances Methods convert :: Value -> Maybe Double Source # convertList :: Value -> Maybe [Double]
Configured Float Source # |
Instance details Defined in Data.Configurator.Instances Methods convert :: Value -> Maybe Float Source # convertList :: Value -> Maybe [Float]
Configured Int Source # |
Instance details Defined in Data.Configurator.Instances Methods convert :: Value -> Maybe Int Source # convertList :: Value -> Maybe [Int]
Configured Word Source # |
Instance details Defined in Data.Configurator.Instances Methods convert :: Value -> Maybe Word Source # convertList :: Value -> Maybe [Word]
RealFloat a => Configured (Complex a) Source # |
Instance details Defined in Data.Configurator.Instances Methods convert :: Value -> Maybe (Complex a) Source # convertList :: Value -> Maybe [Complex a]
Integral a => Configured (Ratio a) Source # |
Instance details Defined in Data.Configurator.Instances Methods convert :: Value -> Maybe (Ratio a) Source # convertList :: Value -> Maybe [Ratio a]
Configured a => Configured [a] Source # |
Instance details Defined in Data.Configurator.Types.Internal Methods convert :: Value -> Maybe [a] Source # convertList :: Value -> Maybe [[a]]
HasResolution a => Configured (Fixed a) Source # |
Instance details Defined in Data.Configurator.Instances Methods convert :: Value -> Maybe (Fixed a) Source # convertList :: Value -> Maybe [Fixed a]
(Configured a, Configured b) => Configured (a, b) Source # |
Instance details Defined in Data.Configurator.Instances Methods convert :: Value -> Maybe (a, b) Source # convertList :: Value -> Maybe [(a, b)]
(Configured a, Configured b, Configured c) => Configured (a, b, c) Source # |
Instance details Defined in Data.Configurator.Instances Methods convert :: Value -> Maybe (a, b, c) Source # convertList :: Value -> Maybe [(a, b, c)]
(Configured a, Configured b, Configured c, Configured d) => Configured (a, b, c, d) Source # |
Instance details Defined in Data.Configurator.Instances Methods convert :: Value -> Maybe (a, b, c, d) Source # convertList :: Value -> Maybe [(a, b, c, d)]

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

data Worth a Source #

Constructors

Required |

Fields

- worth :: a

Optional |

Fields

- worth :: a

#### Instances

Instances details

Functor Worth Source # |
Instance details Defined in Data.Configurator.Types.Internal Methods fmap :: (a -> b) -> Worth a -> Worth b Source # (<$) :: a -> Worth b -> Worth a Source #
IsString (Worth FilePath) Source # |
Instance details Defined in Data.Configurator.Types.Internal Methods fromString :: String -> Worth FilePath Source #
Show a => Show (Worth a) Source # |
Instance details Defined in Data.Configurator.Types.Internal Methods showsPrec :: Int -> Worth a -> ShowS Source # show :: Worth a -> String Source # showList :: [Worth a] -> ShowS Source #
Eq a => Eq (Worth a) Source # |
Instance details Defined in Data.Configurator.Types.Internal Methods (==) :: Worth a -> Worth a -> Bool Source # (/=) :: Worth a -> Worth a -> Bool Source #
Hashable a => Hashable (Worth a) Source # |
Instance details Defined in Data.Configurator.Types.Internal Methods hashWithSalt :: Int -> Worth a -> Int Source # hash :: Worth a -> Int Source #

# Exceptions

data ConfigError Source #

An error occurred while processing a configuration file.

Constructors

ParseError FilePath String |

#### Instances

Instances details

Exception ConfigError Source # |
Instance details Defined in Data.Configurator.Types.Internal Methods toException :: ConfigError -> SomeException Source # fromException :: SomeException -> Maybe ConfigError Source # displayException :: ConfigError -> String Source # backtraceDesired :: ConfigError -> Bool Source #
Show ConfigError Source # |
Instance details Defined in Data.Configurator.Types.Internal Methods showsPrec :: Int -> ConfigError -> ShowS Source # show :: ConfigError -> String Source # showList :: [ConfigError] -> ShowS Source #

data KeyError Source #

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

Constructors

KeyError Name |

#### Instances

Instances details

Exception KeyError Source # |
Instance details Defined in Data.Configurator.Types.Internal Methods toException :: KeyError -> SomeException Source # fromException :: SomeException -> Maybe KeyError Source # displayException :: KeyError -> String Source # backtraceDesired :: KeyError -> Bool Source #
Show KeyError Source # |
Instance details Defined in Data.Configurator.Types.Internal Methods showsPrec :: Int -> KeyError -> ShowS Source # show :: KeyError -> String Source # showList :: [KeyError] -> ShowS Source #

# Notification of configuration changes

data Pattern Source #

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

Instances details

Data Pattern Source # |

Instance details

Defined in Data.Configurator.Types.Internal

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Pattern -> c Pattern Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Pattern Source #

toConstr :: Pattern -> Constr Source #

dataTypeOf :: Pattern -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Pattern) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Pattern) Source #

gmapT :: (forall b. Data b => b -> b) -> Pattern -> Pattern Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Pattern -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Pattern -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Pattern -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Pattern -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Pattern -> m Pattern Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Pattern -> m Pattern Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Pattern -> m Pattern Source #

IsString Pattern Source # |
Instance details Defined in Data.Configurator.Types.Internal Methods fromString :: String -> Pattern Source #
Show Pattern Source # |
Instance details Defined in Data.Configurator.Types.Internal Methods showsPrec :: Int -> Pattern -> ShowS Source # show :: Pattern -> String Source # showList :: [Pattern] -> ShowS Source #
Eq Pattern Source # |
Instance details Defined in Data.Configurator.Types.Internal Methods (==) :: Pattern -> Pattern -> Bool Source # (/=) :: Pattern -> Pattern -> Bool Source #
Hashable Pattern Source # |
Instance details Defined in Data.Configurator.Types.Internal Methods hashWithSalt :: Int -> Pattern -> Int Source # hash :: Pattern -> Int Source #

type ChangeHandler Source #

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.