From 83bad08d7f28143cdaae42156d951b421fa15a8a Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sat, 5 Jul 2014 22:40:54 -0400 Subject: [PATCH] Move pickle_location into the TSN.Location module and update TSN.XML.News. --- src/TSN/Location.hs | 26 ++++++++++++++++++++++++++ src/TSN/XML/News.hs | 17 +---------------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/TSN/Location.hs b/src/TSN/Location.hs index 1097d93..178c6c5 100644 --- a/src/TSN/Location.hs +++ b/src/TSN/Location.hs @@ -14,15 +14,25 @@ -- module TSN.Location ( Location(..), + pickle_location, + -- * WARNING: these are private but exported to silence warnings LocationConstructor(..) ) where -- System imports +import Data.Tuple.Curry ( uncurryN ) import Database.Groundhog () -- Required for some String instance import Database.Groundhog.TH ( defaultCodegenConfig, groundhog, mkPersist ) +import Text.XML.HXT.Core ( + PU, + xpElem, + xpOption, + xpText, + xpTriple, + xpWrap ) -- | Database representation of a location. @@ -52,3 +62,19 @@ mkPersist defaultCodegenConfig [groundhog| type: constraint fields: [city, state, country] |] + + + +-- | We also provide an (un)pickler for one common XML representation, +-- used at least in "TSN.XML.News" and "TSN.XML.Location". +-- +pickle_location :: PU Location +pickle_location = + xpElem "location" $ + xpWrap (from_tuple, to_tuple) $ + xpTriple (xpOption (xpElem "city" xpText)) + (xpOption (xpElem "state" xpText)) + (xpElem "country" xpText) + where + from_tuple = uncurryN Location + to_tuple l = (city l, state l, country l) diff --git a/src/TSN/XML/News.hs b/src/TSN/XML/News.hs index a36ff7e..3f9fef5 100644 --- a/src/TSN/XML/News.hs +++ b/src/TSN/XML/News.hs @@ -53,7 +53,6 @@ import Text.XML.HXT.Core ( xpOption, xpPair, xpText, - xpTriple, xpWrap ) -- Local imports. @@ -63,7 +62,7 @@ import TSN.Codegen ( import TSN.Database ( insert_or_select ) import TSN.DbImport ( DbImport(..), ImportResult(..), run_dbmigrate ) import TSN.Picklers ( xp_time_stamp ) -import TSN.Location ( Location(..) ) +import TSN.Location ( Location(..), pickle_location ) import TSN.XmlImport ( XmlImport(..) ) import Xml ( FromXml(..), @@ -342,20 +341,6 @@ pickle_msg_id = to_tuple m = (db_msg_id m, db_event_id m) --- | Convert a 'Location' to/from XML. --- -pickle_location :: PU Location -pickle_location = - xpElem "location" $ - xpWrap (from_tuple, to_tuple) $ - xpTriple (xpOption (xpElem "city" xpText)) - (xpOption (xpElem "state" xpText)) - (xpElem "country" xpText) - where - from_tuple = - uncurryN Location - to_tuple l = (city l, state l, country l) - -- | Convert a 'Message' to/from XML. -- -- 2.44.2