Dave Cross dave at
Wed May 1 16:30:01 BST 2013

Quoting "Th. J. van Hoesel" <th.j.v.hoesel at>:

> Hello,
> As agreed upon with Dave Cross, I would make some really cool  
> changes to his module Number::Fraction - I as former math teacher  
> love fraction.
> However, can someone point me out what is happening between lines  
> 132 and 144 of ? This part is the neatest part of the  
> module, where it enables the module to use constants in your Perl  
> programs.

Here's the code on github:

And here's the relevant section of the documentation:

> my %_const_handlers =
>   (q => sub { return __PACKAGE__->new($_[0]) || $_[1] });

This defines a subroutine that Perl will use to parse any quoted  
strings. If Number::Fraction->new can construct an object out of them,  
it will. Otherwise new() returns false and the original string is used  

> =head2 import
> Called when module is C<use>d. Use to optionally install constant
> handler.
> =cut
> sub import {
>   overload::constant %_const_handlers if $_[1] and $_[1] eq ':constants';
> }

And this installs the constant handler if the module is used with the  
correct argument (use Number::Fraction ':constants').

Should really give users the option to uninstall that handler too, I guess.



More information about the mailing list