I can declare an attribute with Moose as follows:
has 'attr' => (is => 'rw', isa => 'Int', default => 10);
Is reset possible for this default value?
Example:
$obj->attr(5); # sets attr to 5 $obj->_reset_attr; print $obj->attr; # will print 10
If you do this:
has 'attr' => ( is => 'rw', isa => 'Int', lazy => 1, default => 10, clearer => '_clear_attr', );
then you can do:
my $obj = Class->new; print $obj->attr; # 10 $obj->attr(5); print $obj->attr; # 5 $obj->_clear_attr; print $obj->attr; # 10
The combination of lazy and clearer is important here.
lazy
clearer
Source: https://habr.com/ru/post/1482630/More articles:Is it possible to determine whether an Android device is connected to a computer or just power? - androidConvert string to ConnectionStringSettings - c #JGraphX ββtakes a long time to build a graph - graphvideo.js - controls are not displayed in IE8 - flashBattery Notification - androidASP.NET C # get screen width in pixels - c #Asp.Net Get Screen Width - c #Problem with @ font-face and .ttf files - htmlCan't find the Java error symbol? - javaValueError: invalid literal for int () with base 10: 'stop' - pythonAll Articles