{"_id":"twill","_rev":"17-c3dc3ab6eaa72bca67ea691400c5212f","name":"twill","description":"a clean javascript aspect oriented microframework","dist-tags":{"latest":"0.2.0"},"versions":{"0.0.1":{"name":"twill","version":"0.0.1","description":"a clean javascript aspect oriented microframework","homepage":"http://github.com/gtanner/twill","author":{"name":"gtanner"},"contributors":[{"name":"Gord Tanner","email":"gtanner@gmail.com","url":"http://github.com/gtanner"}],"licenses":[{"type":"MIT","url":"http://www.opensource.org/licenses/mit-license.php"}],"main":"./lib/twill","_id":"twill@0.0.1","dependencies":{},"devDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.0.8","_nodeVersion":"v0.5.0-pre","_defaultsLoaded":true,"dist":{"shasum":"174f90a464705883359b5adf6968eaba4af39075","tarball":"https://registry.npmjs.org/twill/-/twill-0.0.1.tgz","integrity":"sha512-TEHWiGVZqJqExks38b9R/UDu+rjetDEP4Jok52BCqa2PmTSz5Ny2yX0TJAWSKq+OrgfdQlUAyYysQGOKHyaHUA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBTtbLXKyE1I9DdIECQ7QJCWlurHm/TMNglrZK/d+c/SAiBCFSuhBvaYHTCLqgCQPdzp0oFbbf9mNjRYQ+s5lg12YA=="}]},"scripts":{},"directories":{}},"0.0.2":{"name":"twill","version":"0.0.2","description":"a clean javascript aspect oriented microframework","homepage":"http://github.com/gtanner/twill","author":{"name":"gtanner"},"contributors":[{"name":"Gord Tanner","email":"gtanner@gmail.com","url":"http://github.com/gtanner"}],"licenses":[{"type":"MIT","url":"http://www.opensource.org/licenses/mit-license.php"}],"main":"./lib/twill","_id":"twill@0.0.2","dependencies":{},"devDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.0.8","_nodeVersion":"v0.5.0-pre","_defaultsLoaded":true,"dist":{"shasum":"1260989ce60ac25f05d97d0bdd00bab7fa47964a","tarball":"https://registry.npmjs.org/twill/-/twill-0.0.2.tgz","integrity":"sha512-u9CzbRRNf/4NzpGQGtxFsognz4llLt/Y4CGbkX/IRk/BsJv40GtqjP4y/JyEaAaM5WV8vauwqwUWmYN12VPswA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBfVBgEhP0uqauZlW4xTTdrnoamIPH039r8xjgeKxTGGAiBvxxku6GOsyqWaRG477IA2gzm7iLtc2C/kLPiIbaq4yQ=="}]},"scripts":{},"maintainers":[{"name":"gtanner","email":"gtanner@gmail.com"}],"directories":{}},"0.0.3":{"name":"twill","version":"0.0.3","description":"a clean javascript aspect oriented microframework","homepage":"http://github.com/gtanner/twill","author":{"name":"gtanner"},"contributors":[{"name":"Gord Tanner","email":"gtanner@gmail.com","url":"http://github.com/gtanner"}],"licenses":[{"type":"MIT","url":"http://www.opensource.org/licenses/mit-license.php"}],"main":"./lib/twill","_npmUser":{"name":"gtanner","email":"gtanner@gmail.com"},"_id":"twill@0.0.3","dependencies":{},"devDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.0.99","_nodeVersion":"v0.4.5","_defaultsLoaded":true,"dist":{"shasum":"bee55c5568e70511eab689f61299ee790f772f40","tarball":"https://registry.npmjs.org/twill/-/twill-0.0.3.tgz","integrity":"sha512-+0iVSKBy754KBmsN0euaBhZFfB7Vz7czEAng3Uk3RtnRZd6oS5IMhglhiVead9j/82Th4YZ1vOJXP3le8SvlfQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEdH4S5jeAwJ3efDCyjHwqE7sAgL9bVZP+x8SGW7bhb2AiEAu16pY4vbH8EMeu0BfNnVpqMEY8pBeg6J6TctHKT1T2Y="}]},"maintainers":[{"name":"gtanner","email":"gtanner@gmail.com"}],"directories":{}},"0.1.0":{"name":"twill","version":"0.1.0","description":"a clean javascript aspect oriented microframework","homepage":"http://github.com/gtanner/twill","author":{"name":"gtanner"},"contributors":[{"name":"Gord Tanner","email":"gtanner@gmail.com","url":"http://github.com/gtanner"}],"licenses":[{"type":"MIT","url":"http://www.opensource.org/licenses/mit-license.php"}],"main":"./lib/twill","_npmUser":{"name":"gtanner","email":"gtanner@gmail.com"},"_id":"twill@0.1.0","dependencies":{},"devDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.1.0-beta-4","_nodeVersion":"v0.6.6","_defaultsLoaded":true,"dist":{"shasum":"c8fdc4d135538111f6d9e82497ce944333b51cc0","tarball":"https://registry.npmjs.org/twill/-/twill-0.1.0.tgz","integrity":"sha512-2asPIb6I1Mgh+vB9QLpKVicitIIub16ZsYPbf4yxcguOlHtWNUa3wcCVU2FdfVWC2O79e+EGt4+NC2ujJimWOQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC7l0o6TtpxZ8j0B3Ge5eBqP3ft3N8XgTod4BmeJPB/iQIhANvgsGkwnY8guyAf1vttzMVNzf61BDCWWX2XC61pGwRk"}]},"readme":"# twill\nA new approch to javascript aspect oriented programming.  Twill is an attempt to create\nan AOP framework for javascript that feels like it was written for javascript. Twill\nwill run fine in both node and in the browser.\n\n# install\n\n    npm install twill\n\n# example\n\n    var twill = require(\"twill\"),\n        foo = {\n            stuff: function (a,b,c) { \n                console.log(\"stuff\");\n            },\n            things: function () {\n                console.log(\"things\");\n            },\n            foo: function (bar, baz) {\n                console.log(bar);\n                console.log(baz);\n            },\n            baz: function () {\n                throw \"oh noes!\";\n            },\n            ninja: function () {\n            }\n        };\n\n    var foo_aspect = twill.aspect(foo, function (weave) {\n        weave.before.stuff(function (a, b, c) {\n            console.log(\"calling stuff!\");\n        });\n\n        weave.after.things(function (a, b, c) {\n            console.log(\"called things!\");\n        });\n\n        weave.around.foo(function (args, orig) {\n            orig(args[0] || \"default_bar\", args[1] || \"default_baz\");\n        });\n\n\n        weave.exception.baz(function (e) {\n            console.log(e);\n            //just rethrow if you don't want to swallow the exception\n            throw e;\n        });\n\n        weave.add.sweet = function () {\n            console.log(\"dude\");\n        };\n\n        //can be done for before/after/around (around also passes orig)\n        weave.all.after(function (method, args) {\n            window.stats.track(method);\n            console.log(\"stats +1 for \" + method);\n        });\n\n        weave.add.dude = function () {\n            console.log(\"sweet\");\n        };\n\n        weave.remove.ninja();\n    });\n\n    foo.stuff(\"one\", \"two\", \"three\");\n    // calling stuff\n    // stuff\n    // stats +1 for stuff\n\n    foo.things(1,2,3);\n    //things\n    //called things\n    //status +1 for things\n\n    foo.foo();\n    //default_bar\n    //default_baz\n    //stats +1 for things\n\n    foo.sweet();\n    //dude\n    //stats +1 for sweet\n\n    foo.dude();\n    //sweet\n\n    twill.unweave(foo_aspect);\n\n    foo.stuff(\"one\", \"two\", \"three\");\n    // stuff\n\n    foo.things(1,2,3);\n    //things\n\n    foo.foo();\n    //undefined\n    //undefined\n\n    foo.sweet();\n    //method not defined\n\n    foo.dude();\n    //method not defined\n\n# todo:\n\nThis is a very early release and not everything is done just yet. \nStill todo:\n- make it work in the browser\n\n# how to develop\n\nall code should have tests written in node-unit. Run the tests with:\n\n    jake test\n\n","maintainers":[{"name":"gtanner","email":"gtanner@gmail.com"}],"directories":{}},"0.2.0":{"name":"twill","version":"0.2.0","description":"a clean javascript aspect oriented microframework","homepage":"http://github.com/gtanner/twill","author":{"name":"gtanner"},"contributors":[{"name":"Gord Tanner","email":"gtanner@gmail.com","url":"http://github.com/gtanner"}],"licenses":[{"type":"MIT","url":"http://www.opensource.org/licenses/mit-license.php"}],"main":"./lib/twill","readme":"# twill\n\nA new approch to javascript aspect oriented programming.  Twill is an attempt to create\nan AOP framework for javascript that feels like it was written for javascript. Twill\nwill run fine in both node and in the browser.\n\n## install\n\ntwill can be installed via npm:\n\n    npm install twill\n\nusing in node:\n\n    var twill = require('twill');\n\n    twill.aspect(foo, advice);\n\nor in the browser:\n\n    <script type=\"text/javascript\" src=\"twill.js\"></script>\n\n    <script type=\"text/javascript\">\n        twill.aspect(foo, advice);\n    </script>\n\n## Using Twill\n\nto use twill you start with the aspect method.\n\n    var id = twill.aspect(target, function (weave) {\n    };\n\nThe id returned is used to unweave any changes made to the target \n\n    twill.unweave(id);\n\nTthe function passed to aspect is called the advice.  This is where\nyou define the pointcuts you wish to weave onto the target.\n\n## the weave object\n\nAll of the functionality of twill is handed via the weave object exposed\nto the advice function.\n\nthe weave object allows adding pointcuts for various pointcuts on the\nthe target. A property is added to the weave object for each of the \nfunctions on the target.\n\n    weave.<method>.<pointcut_location>();\n\n### The Before Pointcut\n\nAdding a pointcut before allows you to run the aspect code before the original method \nis called. You have access to the parameters passed in but can not change them.\n\n    var target = {\n        addTwelve: function (a) { return a + 12; }\n    };\n\n    twill.aspect(target, function (weave) {\n        weave.addTwelve.before(function (a) {\n            console.log(\"the value passed in was: \" + a);\n        });\n    });\n\n### The After Pointcut\n\nAdding a pointcut after allows you to run the aspect to after the original method was called.\nYou have access to the paramters passed in but can not change them.  You don't have access to the\nreturn value and can not change it.\n\n    var target = {\n        takeOverTheWorld: function () {\n            return false;\n        }\n    };\n\n    twill.aspect(target, function (weave) {\n        weave.takeOverTheWorld.after(function () {\n            world.warn();\n        });\n    });\n\n### The Around Pointcut\n\nAdding a pointcut around gives you the most flexability. This allows you to wrap around\nthe method being called and both change the parameters in and the return value out.\n\n    var target = {\n        add: function (a, b) { return a + b; } \n    };\n\n    twill.aspect(target, function (weave) {\n        weave.around.add(function (args, orig) {\n            return orig(args[0] + 1, args[1] + 1) * 2;\n        });\n    });\n\n    target.add(2, 2);\n    //returns 12;\n\n### The Exception Pointcut\n\nThis pointcut allows you to act when a method throws an exception.\n\n    var target = {\n        onnoes: function () {\n            throw \"snap\";\n        }\n    };\n\n    twill.aspect(target, function (weave) {\n        weave.exeception.onnoes(function (e) {\n            console.log(e);\n    \n            //just rethrow if you don't want to swallow\n            throw e;\n        });\n    });\n    \n### The Add Pointcut\n\nAllows you to add methods to the target. The bonus is that you will \nable to remove them when calling unweave.\n\n    var target = {};\n\n    twill.aspect(target, function (weave) {\n        weave.add.woot = function () {\n            console.log(\"woot\");\n        };\n    });\n\n### The Remove Pointcut\n\nAllows you to remove methods on the target. The same bonus as add\nwhere you can have this undone when unweaving the target.\n\n    var target = {\n        getPassword: function () {\n            return \"password\";\n        }\n    };\n\n### The All property\n\nThis property on the weave object allows you to aspect all\nof the methods on the target (at the time of calling) with\na single advice.  This is availbe for the following pointcuts:\n * before\n * after\n * around\n\nThe advice is called with: `function (methodName, arguments, method) {}`\n\nExample:\n\n    twill.aspect(target, function (weave) {\n        weave.all.after(function (method, args) {\n            window.stats.track(method);\n            console.log(\"stats +1 for \" + method);\n        });\n\n        weave.all.around(function (method, args, orig) {\n            console.log(method);\n            return orig.apply(orig, args);\n        });\n    });\n\n# how to develop\n\nall code should have tests written in node-unit. Run the tests with:\n\n    jake test\n\n","_id":"twill@0.2.0","dist":{"shasum":"f280061a20aa1a7ab42df5d712ad91df170892c1","tarball":"https://registry.npmjs.org/twill/-/twill-0.2.0.tgz","integrity":"sha512-vyTMK0jfPG1FuiBsVpxi6Rn8ARmBgeg/A0LX4BYNwfy8MeSjkMXj5sJH2HR2/U/2PmaiqP+CRG13J0Pq71zMJg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICovJd5FsKqn0ogyf3XQTG3p8iWzvxlXQAiVkD56p/NpAiEAw8orStwBDmE9l0jIaIievRn6eo4Mv4bWbq5iP45QQ8Q="}]},"_npmVersion":"1.1.61","_npmUser":{"name":"gtanner","email":"gtanner@gmail.com"},"maintainers":[{"name":"gtanner","email":"gtanner@gmail.com"}]}},"maintainers":[{"name":"gtanner","email":"gtanner@gmail.com"}],"time":{"modified":"2022-06-28T00:07:32.294Z","created":"2011-06-04T02:29:13.126Z","0.0.1":"2011-06-04T02:29:13.672Z","0.0.2":"2011-08-16T02:14:04.465Z","0.0.3":"2012-02-28T03:00:29.771Z","0.1.0":"2012-03-13T19:06:08.815Z","0.2.0":"2013-02-27T03:45:14.980Z"},"author":{"name":"gtanner"}}