|
|
MillionMunkeys ->
Products ->
PiMunkey™ ->
PiMunkey™ is a ColdFusion implementation of Property-Invocation (Pi) Programming. It consists of a single CFC that adheres to all of the standards of Pi Programming. To create a Pi-style object, just extend this CFC, and use the built-in functions.
What's New
Version 1.4 (released on September 29th, 2011):
- Added a new Javascript PiObject class for Javascript coders!
- If you are only setting one property at a time, the set function now returns the value passed to it.
Version 1.3 (released on March 16th, 2011):
- Fixed a bug where filters didn't behave as expected when they didn't return a value.
- Now allows listeners to override a removal.
- Added two new private scopes for those variables you don't want to expose to other objects.
- getPrivate() returns a scope that is only available from within an object.
- getProtected() returns a scope that is available from within an object and to other objects in the same folder.
- Added the toStruct(depth) function for easier debugging.
Want to Dive Right In?
About Property-Invocation (Pi) Programming™
Pi Programming is a style of programming. It shares in philosophy with JavaBeans to say that every property can only be modifed using "getter" and "setter" functions. It is also a close cousin to Implicit-Invocation Programming which allows any object to listen for a broadcast message, and lie dormant until someone broadcasts that message.
Getters & Setters
Pi Programming differs from JavaBeans in that you don't write your own getter and setter functions. Instead you use a standard set of functions on all objects.
- exists: Tells you whether a property exists on an object.
- get: Returns the stored value for that property.
- set: Assigns a stored value to a property name.
- remove: Removes a property from an object.
Property Invocation vs. Events
Property Invocation differs from Implicit Invocation in that you don't have to register any events. Instead, every "get" and "set" event becomes a potential plugin point for infinite extendability. And to make it happen you only need to create one of two types of functions.
- listener: This type of function is fired on a "set" operation, allowing the function to react to and/or modify the variable after it has been added to the object.
- filter: This type of function is fired on a "get" operation, allowing the function to react to and/or modify the variable before it is returned to the requesting function.
Struct vs. Array Notation
Collections of data in ColdFusion are commonly stored in either structures or arrays. With Pi Programming, both are handled by the same object. This standardizes object interactions, and makes everything extensible.
- struct notation: Named properties are added by their IDs, and can be accessed in the same way. They can be added one at a time or in batches.
<cfset page = CreateObject("component","MillionMunkeys.PiMunkey.PiComponent") />
<cfset page.set("id","page1") />
<cfset page.set(title="First Page", template="firstpage.cfm",
group="products") />
<cfset page.remove("group") />
<cfreturn page.get("title") />
- array notation: Ordered arrays are not accessed by named attributes, but by their index within the object. You can use the "add", "insertAt", and "remove" functions to add and remove properties based on their location in the object, rather than their name.
<cfset site = CreateObject("component","MillionMunkeys.PiMunkey.PiComponent") />
<cfset page1 = CreateObject("component","MillionMunkeys.PiMunkey.PiComponent") />
<cfset page2 = CreateObject("component","MillionMunkeys.PiMunkey.PiComponent") />
<cfset index = site.add(page2) />
<cfset site.insertAt(index,page1) />
<cfset site.remove(2) />
|

|