There are suggestions about how to get status here: Mac OS X - Bash script if statement based on system status
And then you might call a script from launchd.plist every so many seconds... Something like this. Not sure about how to run the shutdown as root without entering a password (when the lid is closed!)
#!/bin/bash #power down on close lid
clamshell_status=if ioreg -r -k AppleClamshellState | grep '"AppleClamshellState"' | cut -f2 -d"="
if [[ ${clamshell_status} == "YES" ]] then shutdown -h now fi
#!/bin/bash
#power down on close lid
clamshell_status=if ioreg -r -k AppleClamshellState | grep '"AppleClamshellState"' | cut -f2 -d"="
if [[ ${clamshell_status} == "YES" ]]
then
shutdown -h now
fi