[Catalyst] Re: using Plugin::Singleton and testing
Adam Clarke
adam.clarke at strategicdata.com.au
Fri Nov 17 06:13:13 GMT 2006
On 17/11/2006, at 4:37 PM, Jonathan Rockway wrote:
> On Thursday 16 November 2006 20:08, A. Pagaltzis wrote:
>> A singleton is nothing but a global variable, except the
>> identifier comes from the class namespace rather than the
>> variable namespace. Put it in a global variable already.
>
> Not entirely true. Try this:
>
> $global = "Oops, accidentally overwrote the instance with garbage.";
>
> vs.
>
> Singleton->get_instance() = "Oops, accidentally overwrote the
> instance.";
Not really, because ...
use Readonly;
Readonly my $global => "Warming";
print "Before => $global\n\n";
eval {
$global = "Oops, accidentally overwrote the instance with
garbage.";
};
if ($@) { print "Error (would have died if uneval'd) => $@\n"; };
print "After => $global\n";
produces ...
Before => Warming
Error (would have died if uneval'd) => Modification of a read-
only value attempted at t.pl line 8
After => Warming
No matter what my prime minister says.
Cheers
--
Adam Clarke
www.strategicdata.com.au
More information about the Catalyst
mailing list