moduleNetwork.Shpider.Forms(moduleNetwork.Shpider.Pairs,Form(..),Method(..),gatherForms,fillOutForm,allForms,toForm,mkForm)whereimportData.MaybeimportqualifiedData.MapasMimportText.HTML.TagSoup.ParsecimportNetwork.Shpider.TextUtilsimportNetwork.Shpider.Pairs-- | Either GET or POST.dataMethod=GET|POSTderivingShow-- | Plain old form: Method, action and inputs.dataForm=Form{method::Method,action::String,inputs::M.MapStringString}derivingShow-- | Takes a form and fills out the inputs with the given [ ( String , String ) ].-- It is convienent to use the `pairs` syntax here.---- @-- f : _ <- `getFormsByAction` \"http:\/\/whatever.com\"-- `sendForm` $ `fillOutForm` f $ `pairs` $ do-- \"author\" =: \"Johnny\"-- \"message\" =: \"Nice syntax dewd.\"-- @fillOutForm::Form->[(String,String)]->FormfillOutFormfis=foldl(\form(n,v)->form{inputs=M.insertnv$inputsform})fis-- | The first argument is the action attribute of the form, the second is the method attribute, and the third are the inputs.mkForm::String->Method->[(String,String)]->FormmkFormamps=Form{action=a,method=m,inputs=M.fromListps}-- | Gets all forms from a list of tags.gatherForms::[Tag]->[Form]gatherForms=tParseallForms-- | The `TagParser` which parses all forms.allForms::TagParser[Form]allForms=dofs<-allWholeTags"form"return$mapMaybetoFormfstoForm::WholeTag->MaybeFormtoForm(TagOpen_attrs,innerTags,_)=dom<-methodLookupattrsa<-attrLookup"action"attrsletis=tParse(allOpenTags"input")innerTagstas=tParse(allWholeTags"textarea")innerTagsJust$Form{inputs=M.fromList$mapMaybeinputNameValueis++mapMaybetextAreaNameValuetas,action=a,method=m}methodLookupattrs=dom<-attrLookup"method"attrscaselowercasemof"get"->JustGET"post"->JustPOSTotherwise->NothinginputNameValue(TagOpen_attrs)=dov<-caseattrLookup"value"attrsofNothing->Just""j@(Just_)->jn<-attrLookup"name"attrsJust(n,v)textAreaNameValue(TagOpen_attrs,inner,_)=doletv=innerTextinnern<-attrLookup"name"attrsJust(n,v)