High-Level Server Side Web Scripting

Arya MirΛογισμικό & κατασκευή λογ/κού

15 Μαϊ 2012 (πριν από 5 χρόνια και 4 μήνες)

551 εμφανίσεις

PADL2001
High-LevelServerSideWebScriptingin
MichaelHanus
Christian-Albrechts-Universit
¨
atKiel
1
HTML/CGIP
ROGRAMMING
EarlydaysoftheWorldWideWeb:
webpageswithstaticcontents
CommonGatewayInterface(CGI):
webpageswithdynamiccontents
Retrievalofadynamicpage:
➜serverexecutesaprogram
➜programcomputesanHTMLstring,writesittostdout
➜serversendsresultbacktoclient
HTMLwithinputelements(forms):
➜clientfillsoutinputelements
➜inputvaluesaresenttoserver
➜serverprogramdecodesinputvaluesforcomputingitsanswer
HTML/CGIP
ROGRAMMING
2
T
RADITIONAL
CGIP
ROGRAMMING
CGIprogramsontheservercanbewritteninanyprogramminglanguage
➜accesstoenvironmentvariables(forinputvalues)
➜writesastringtostdout
Scriptinglanguages:
(Perl,Tcl,...)
➜simpleprogrammingofsinglepages
➜error-prone:correctnessofHTMLresultnotensured
➜difficultprogrammingofinteractionsequences
Specializedlanguages:
(MAWL,DynDoc,...)
➜HTMLsupport(structurechecking)
➜interactionsupport(partially)
➜restrictedorconnectiontoexistinglanguages
TRADITIONAL
CGIP
ROGRAMMING
3
CGIP
ROGRAMMINGINA
M
ULTI
-P
ARADIGM
L
ANGUAGE
Libraryinmulti-paradigmlanguage
Exploitfunctionalandlogicfeaturesfor
➜HTMLsupport(datatypeforHTMLstructures)
➜simpleaccesstoinputvalues(freevariablesandenvironments)
➜simpleprogrammingofinteractions(eventhandlers)
➜wrapperforhidingdetails
Exploitimperativefeaturesfor
➜environmentaccess(files,databases,...)
Domain-specificlanguageforHTML/CGIprogramming
CGIP
ROGRAMMINGINA
MULTI
-P
ARADIGM
L
ANGUAGE
4
C
URRY
[Dagstuhl’96,POPL’97]

multi-paradigmlanguage
(higher-orderconcurrentfunctionallogiclanguage,
featuresforhigh-leveldistributedprogramming)

extensionofHaskell
(non-strictfunctionallanguage)

developedbyaninternationalinitiative

provideastandardforfunctionallogiclanguages
(research,teaching,application)

severalimplementationsavailable
C
URRY
5
VALUES
Valuesinimperativelanguages:
basictypes+pointerstructures
Declarativelanguages:
algebraicdatatypes
(Haskell-likesyntax)




 














































































Value

dataterm
,
constructorterm
:
well-formedexpressioncontainingvariablesanddatatypeconstructors










































VALUES
6
C
URRY
P
ROGRAMS
Functions
:operationsonvaluesdefinedby
equations
(or
rules
)











defined
operation
dataterms
condition
(optional)
expression

 








 

 







































 





















C
URRY
P
ROGRAMS
7
E
XPRESSIONS





(constants)

(variables

)











(application)





(abstraction)














(conditional)
(equationalconstraint)
(concurrentconjunction)
(existentialquantification)
Equationalconstraintsoverfunctionalexpressions:
Furtherconstraints:
realarithmetic,finitedomain,ports
E
XPRESSIONS
8
E
XPRESSIONS





(constants)

(variables

)











(application)





(abstraction)














(conditional)







(equationalconstraint)





(concurrentconjunction)


















(existentialquantification)
Equationalconstraintsoverfunctionalexpressions:
Furtherconstraints:
realarithmetic,finitedomain,ports
E
XPRESSIONS
8-a
E
XPRESSIONS





(constants)

(variables

)











(application)





(abstraction)














(conditional)







(equationalconstraint)





(concurrentconjunction)


















(existentialquantification)
Equationalconstraintsoverfunctionalexpressions:

 






















 



Furtherconstraints:
realarithmetic,finitedomain,ports
E
XPRESSIONS
8-b
F
UNCTIONS

lazyevaluation(evaluateonly
needed
redexes)

supportinfinitedatastructures,modularity

optimalevaluation(alsoforlogicprogramming)
Distinguish:
flexible
(generator)and
rigid
(consumer)functions
Flexiblefunctions

logicprogramming
Rigidfunctions

concurrentprogramming
FUNCTIONS
9
F
LEXIBLEVS
.R
IGID
F
UNCTIONS












rigid/flexiblestatusnotrelevantforgroundcalls:





flexible:



























rigid:







suspend
























(suspend


)











(evaluate


)










DefaultinCurry:constraintsareflexible,allothersarerigid
FLEXIBLEVS
.R
IGID
F
UNCTIONS
10
M
ODELING
HTML
DatatypeforrepresentingHTMLexpressions:







 










 






 




 






 





 







 





Someusefulabbreviations:













 















 




 









 















 


















 


































 



























Example:











































 

















1.HelloWorld
Helloworld!
MODELING
HTML11
Advantages:
➜staticcheckingofHTMLstructure(well-balancedparentheses)
➜flexibledynamicdocuments
➜functionsforcomputingHTMLdocuments
Convertingtreestructure(leavescontainstrings)intonestedHTMLlists:






















 










 







 






 




















 








 
















 




 















 









 
















 

































 













MODELING
HTML12
HTMLI
NPUT
F
ORMS
SpecificHTMLelementsfordealingwithuserinput



























 














Formissubmitted

clientssendsthecurrentvalueofthisfield(identifiedby








)
ExpressibleasHTMLterm:


 












































 

















Problems:
➜serverprogrammustdecodeinputvalues
➜serverprogrammustknowrightnamesoffieldidentifiers(






)
➜error-prone
HTMLI
NPUT
F
ORMS
13
A
BSTRACT
I
NPUT
F
ORMS
Solution:
➜usefreevariablesasreferencestoinputfields(
CGIreferences
)
➜collectinputvaluesin
CGIenvironments
:
mappingfromCGIreferencestostrings
➜associate
eventhandlers
tosubmitbuttons
➜eventhandlerstakeaCGIenvironmentandproduceanHTMLform
Implementation:
straightforwardinafunctionallogiclanguage!
A
BSTRACT
INPUT
FORMS
14
A
BSTRACT
I
NPUT
F
ORMS
:I
MPLEMENTATION
CGIreferences:



 




 




 











 











 


➜noconstructionofwrongreferences
➜onlyfreevariablesoftype




➜globalwrapperfunctioninstantiateswiththerightstrings
HTMLelementswithCGIreferences:



 










 





 





 


Example:
TextfieldswithaCGIreferenceandinitialcontents










 






 






 













 















 







 







































 






 









 






A
BSTRACT
INPUT
FORMS
:IMPLEMENTATION
15
HTMLform:
title+listofHTMLexpressions



 







 


 





 





Example:simpleformwithasingleinputelement(atextfield)




















 






















 




















CGIenvironments:
mapCGIreferencestostrings


 

 





 





 



Eventhandlers
havetype

 








 

Eventhandlersareassociatedtosubmitbuttons:
userpressesasubmitbutton

executeassociatedeventhandlerwithcurrentenvironment
A
BSTRACT
INPUT
FORMS
:IMPLEMENTATION
16
E
XAMPLE
:F
ORMTO
R
EVERSE
/D
UPLICATEA
S
TRING










 













 













 












 






 






 


 







 









 






 


 



 



 






















 












































 








 













 











































 







 





E
XAMPLE
:FORMTO
R
EVERSE
/D
UPLICATEA
STRING
17
ACCESSINGTHE
W
EB
S
ERVER
E
NVIRONMENT
Formtoshowthecontentsofanarbitraryfilestoredattheserver:























































 

















 















 









 
































 




















































 





A
CCESSINGTHE
WEB
S
ERVER
E
NVIRONMENT
18
H
ANDLING
I
NTERMEDIATE
S
TATE
Sequenceofformstocollectfirstandlastname:




























































 




 











 













 







 






























 

































 
 







 



 














 









 















































H
ANDLING
I
NTERMEDIATE
S
TATE
19
I
NTERACTION
S
EQUENCES
Programmingarbitraryloops:anumberguessinggame:












 








 









































 























 




 









 








 

















 




































 
































 
 




















 















































INTERACTION
S
EQUENCES
20
A
PPLICATION
-
ORIENTED
A
BSTRACTIONS
Abtraction:
HTMLelementforlookingupemailaddresses:






 








































 














 









 















































Now,






 



canbeusedasanyotherHTMLelement
(withoutnameconflictswithotherformelements!)
:

































 








A
PPLICATION
-
ORIENTED
A
BSTRACTIONS
21
HTML/CGIP
ROGRAMMING
Themainformisexecutedbyawrapperfunction




 



 








 











➜takesatitlestringandaformandtransformsitintoHTMLtext
➜replacesallCGIreferencesbyuniquestrings
➜decodesinputvaluesandinvokesassociatedeventhandler
EventhandlersreturnformsratherthanHTMLexpressions
➜sequencesofinteractions
➜usecontrolabstractions(branching,recursion)ofunderlyinglanguage
➜statebetweeninteractionshandledbyCGIenvironments
Note:
nolanguageextensionnecessary
(
CGIlibrary
)
multi-paradigmlanguagesas
scriptinglanguages
HTML/CGIP
ROGRAMMING
22
I
MPLEMENTATION
➜completelyimplementedinCurry
➜standardCGIprogrammingfeaturesused
➜noserverextension,usablewithanystandardwebserver,nocookies
➜availableaslibraryfor
PAKCS(PortlandAachenKielCurrySystem)






 





 


 















➜basedonaCurry

Prologcompiler
[Antoy/HanusFroCoS’00]
Applications:
➜webpagesforCurry
➜accesstodistributedaddressserver
[PPDP’99]
➜submissionformforJFLP
(JournalofFunctionalandLogicProgramming)
➜questionairesforstudents
➜testinghomeassignmentsofstudents
➜...
IMPLEMENTATION
23
C
ONCLUSIONS
Domain-specificlanguageforHTML/CGIprogramming
(CGIlibrary)
Exploitfunctionalandlogicfeaturesfor
➜correctHTMLcoding(datatypeforHTMLstructures)
➜simpleaccesstoinputvalues(freevariablesandenvironments)
➜simpleprogrammingofinteractions(eventhandlers)
➜wrapperforhidingdetails
Currysupportsappropriateabstractionsforsoftwaredevelopment
Otherexamples:
➜GUIprogramming
[PADL’00]
➜FLparsercombinators
[Caballero/Lopez-FraguasFLOPS’99]
MoreinfosonCurry:

















 















 


C
ONCLUSIONS
24