Using Traits to Maintain State
by Curtis Poe
Some of you might recall chromatic's review of Class::Trait, a module which implements traits (PDF) in Perl. He gave a couple of good examples of how one can use traits and I figured a follow-up on one of my many "real world" uses of traits and how it has simplified my code.
There is a typo in the final line of code which reads:
|Matt S Trout
|I would've thought you could just load Class::InsideOut and use register/id/private to store your data. It should handle all the cleanup etc. for you.|
Matt: I've also had Object::InsideOut suggested, but when I've tested it, this cleanup does not happen. The calling code does not change, but my trait now looks like this:
That Dumper call in the END block shows that the id is still hanging around and that's the problem I need to solve.