わかった気になる
わかった気になる
  gitit-0.8
  gitit-0.8
   初心者Haskell勉強会

  Kiwamu Okabe
1/12

ルーティング
2/12
   monadplus
handlerをmplusで結合してるだ
けに見えます。失敗はmzeroにな
るんですが、成功した場合には次
のhandlerを実行してほしくないよ
うに見えるのですが、、、そー
ゆーもの???
3/12

ページ表示
indexPage :: Handler
indexPage = do
  path' <- getPath
  base' <- getWikiBase
  let prefix' = if null path' then "" else path' ++ "/"
  fs <- getFileStore
  listing <- liftIO $ directory fs prefix'
  let isDiscussionPage (FSFile f) = isDiscussPageFile f
      isDiscussionPage (FSDirectory _) = False
  let prunedListing = filter (not . isDiscussionPage) listing
  let htmlIndex = fileListToHtml base' prefix' prunedListing
  formattedPage defaultPageLayout{
                  pgPageName = prefix',
                  pgShowPageTools = False,
                  pgTabs = [],
                  pgScripts = [],
                  pgTitle = "Contents"} htmlIndex
4/12

              gitアクセス
                                                                                (*1)
 getFileStoreでFileStoreを呼出
     randomPage :: Handler
     randomPage = do
       fs <- getFileStore
       files <- liftIO $ index fs
       let pages = map dropExtension $
                     filter (f -> isPageFile f && not (isDiscussPageFile f)) files
       base' <- getWikiBase
       if null pages
          then error "No pages found!"




(*1)http://hackage.haskell.org/packages/archive/filestore/
latest/doc/html/Data-FileStore-Types.html
5/12

         認証
authenticateUserThat predicate level handler = do
  cfg <- getConfig
  if level <= requireAuthentication cfg
     then do
       mbUser <- getLoggedInUser
       rq <- askRq
       let url = rqUri rq ++ rqQuery rq
       case mbUser of
            Nothing   -> tempRedirect ("/_login?" ++
                         urlEncodeVars [("destination", url)]) $ toResponse ()
            Just u    -> if predicate u
                            then handler
                            else error "Not authorized."
     else handler
6/12

          gititプラグイン#1

    gitit/Network/Gitit/Plugins.hs
                                                (*2)
 がプラグイン読み込みコード。
(*2)詳細は http://www.bluishcoder.co.nz/2008/11/dynamic-
compilation-and-loading-of.html を参照
7/12

       gititプラグイン#2
loadPlugin :: FilePath -> IO Plugin
loadPlugin pluginName = do
--snip--
      pr <- findModule (mkModuleName "Prelude") Nothing
      i <- findModule (mkModuleName "Network.Gitit.Interface") Nothing
      m <- findModule (mkModuleName modName) Nothing
      setContext []
#if MIN_VERSION_ghc(7,0,0)
        [(m, Nothing), (i, Nothing), (pr, Nothing)]
#else
        [m, i, pr]
#endif
      value <- compileExpr (modName ++ ".plugin :: Plugin")
      let value' = (unsafeCoerce value) :: Plugin
      return value'
8/12

        ghc7だと動かない
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 6.12.1
$ gitit -f default.conf
Loading plugin 'plugins/TwitterUrl.hs'...
Finished loading plugins.
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.0.3
$ gitit -f default.conf
Loading plugin 'plugins/TwitterUrl.hs'...
gitit: This ELF file contains no symtab
gitit: gitit: panic! (the 'impossible' happened)
  (GHC version 7.0.3 for x86_64-unknown-linux):
       loadArchive "/usr/lib/ghc-7.0.3/ghc-7.0.3/libHSghc-7.0.3.a": failed

Please report this as a GHC bug:   http://www.haskell.org/ghc/reportabug
9/12

plugins良いらしい
10/12

     plugins使い方#1
API.hs
     module API where

     data Test = Test {
                     field :: String
            }

     test :: Test
     test = Test { field = "default value" }
11/12

     plugins使い方#2
Test.hs
 module Test where

 import API

 resource = test { field = "success" }
12/12

    plugins使い方#3
Main.hs
     import System.Plugins
     import API

     main = do
             m_v <- load_ "../Test.o" ["../api"] "resource"
             v <- case m_v of
                     LoadFailure _   -> error "load failed"
                     LoadSuccess _ v -> return v
             let s = field v
             print s -- => "success"と表示

More Related Content

PDF
GHCソースコード読みのススメ
PDF
Javascript Continues Integration in Jenkins with AngularJS
PDF
Application Logging With Logstash
PDF
Puppet Camp 2012
PDF
G*なクラウド ~雲のかなたに~
PDF
PDF
G* on GAE/J 挑戦編
PDF
Asynchronous PHP and Real-time Messaging
GHCソースコード読みのススメ
Javascript Continues Integration in Jenkins with AngularJS
Application Logging With Logstash
Puppet Camp 2012
G*なクラウド ~雲のかなたに~
G* on GAE/J 挑戦編
Asynchronous PHP and Real-time Messaging

What's hot (20)

PDF
Vancouver presentation
PPTX
PDF
React PHP: the NodeJS challenger
PDF
HTML5 tutorial: canvas, offfline & sockets
PDF
JDD 2017: Nginx + Lua = OpenResty (Marcin Stożek)
PPTX
Synapse india basic php development part 1
PDF
Application Logging With The ELK Stack
KEY
いろいろ
PDF
Plone Conference 2008 Lightning Talk Static Zope Rpx
PPT
GDG DevFest 2013 - PHP Web Apps on Google Cloud
TXT
Simple php backdoor_by_dk
PDF
Using ngx_lua in UPYUN
PPT
Php Mysql
PPTX
App-o-Lockalypse now!
PDF
PDO Basics - PHPMelb 2014
PDF
LogStash - Yes, logging can be awesome
PDF
2018-06-06 @nuxtjs/auth with Django Rest Framework
PDF
Profiling with Xhprof
PDF
Caching. api. http 1.1
PDF
Intro django
Vancouver presentation
React PHP: the NodeJS challenger
HTML5 tutorial: canvas, offfline & sockets
JDD 2017: Nginx + Lua = OpenResty (Marcin Stożek)
Synapse india basic php development part 1
Application Logging With The ELK Stack
いろいろ
Plone Conference 2008 Lightning Talk Static Zope Rpx
GDG DevFest 2013 - PHP Web Apps on Google Cloud
Simple php backdoor_by_dk
Using ngx_lua in UPYUN
Php Mysql
App-o-Lockalypse now!
PDO Basics - PHPMelb 2014
LogStash - Yes, logging can be awesome
2018-06-06 @nuxtjs/auth with Django Rest Framework
Profiling with Xhprof
Caching. api. http 1.1
Intro django
Ad

わかった気になるgitit-0.8

  • 1. わかった気になる わかった気になる gitit-0.8 gitit-0.8 初心者Haskell勉強会 Kiwamu Okabe
  • 3. 2/12 monadplus handlerをmplusで結合してるだ けに見えます。失敗はmzeroにな るんですが、成功した場合には次 のhandlerを実行してほしくないよ うに見えるのですが、、、そー ゆーもの???
  • 4. 3/12 ページ表示 indexPage :: Handler indexPage = do path' <- getPath base' <- getWikiBase let prefix' = if null path' then "" else path' ++ "/" fs <- getFileStore listing <- liftIO $ directory fs prefix' let isDiscussionPage (FSFile f) = isDiscussPageFile f isDiscussionPage (FSDirectory _) = False let prunedListing = filter (not . isDiscussionPage) listing let htmlIndex = fileListToHtml base' prefix' prunedListing formattedPage defaultPageLayout{ pgPageName = prefix', pgShowPageTools = False, pgTabs = [], pgScripts = [], pgTitle = "Contents"} htmlIndex
  • 5. 4/12 gitアクセス (*1) getFileStoreでFileStoreを呼出 randomPage :: Handler randomPage = do fs <- getFileStore files <- liftIO $ index fs let pages = map dropExtension $ filter (f -> isPageFile f && not (isDiscussPageFile f)) files base' <- getWikiBase if null pages then error "No pages found!" (*1)http://hackage.haskell.org/packages/archive/filestore/ latest/doc/html/Data-FileStore-Types.html
  • 6. 5/12 認証 authenticateUserThat predicate level handler = do cfg <- getConfig if level <= requireAuthentication cfg then do mbUser <- getLoggedInUser rq <- askRq let url = rqUri rq ++ rqQuery rq case mbUser of Nothing -> tempRedirect ("/_login?" ++ urlEncodeVars [("destination", url)]) $ toResponse () Just u -> if predicate u then handler else error "Not authorized." else handler
  • 7. 6/12 gititプラグイン#1 gitit/Network/Gitit/Plugins.hs (*2) がプラグイン読み込みコード。 (*2)詳細は http://www.bluishcoder.co.nz/2008/11/dynamic- compilation-and-loading-of.html を参照
  • 8. 7/12 gititプラグイン#2 loadPlugin :: FilePath -> IO Plugin loadPlugin pluginName = do --snip-- pr <- findModule (mkModuleName "Prelude") Nothing i <- findModule (mkModuleName "Network.Gitit.Interface") Nothing m <- findModule (mkModuleName modName) Nothing setContext [] #if MIN_VERSION_ghc(7,0,0) [(m, Nothing), (i, Nothing), (pr, Nothing)] #else [m, i, pr] #endif value <- compileExpr (modName ++ ".plugin :: Plugin") let value' = (unsafeCoerce value) :: Plugin return value'
  • 9. 8/12 ghc7だと動かない $ ghc --version The Glorious Glasgow Haskell Compilation System, version 6.12.1 $ gitit -f default.conf Loading plugin 'plugins/TwitterUrl.hs'... Finished loading plugins. $ ghc --version The Glorious Glasgow Haskell Compilation System, version 7.0.3 $ gitit -f default.conf Loading plugin 'plugins/TwitterUrl.hs'... gitit: This ELF file contains no symtab gitit: gitit: panic! (the 'impossible' happened) (GHC version 7.0.3 for x86_64-unknown-linux): loadArchive "/usr/lib/ghc-7.0.3/ghc-7.0.3/libHSghc-7.0.3.a": failed Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
  • 11. 10/12 plugins使い方#1 API.hs module API where data Test = Test { field :: String } test :: Test test = Test { field = "default value" }
  • 12. 11/12 plugins使い方#2 Test.hs module Test where import API resource = test { field = "success" }
  • 13. 12/12 plugins使い方#3 Main.hs import System.Plugins import API main = do m_v <- load_ "../Test.o" ["../api"] "resource" v <- case m_v of LoadFailure _ -> error "load failed" LoadSuccess _ v -> return v let s = field v print s -- => "success"と表示