The syntax use Foo qw(:const)
uses the EXPORT_TAGS function in Exporter .
When you set up your library module, you usually have a bunch of functions or class variables. Then you configure Exporter, telling it what to export by default
package Foo; use Exporter; our @EXPORT = qw( frobnicate ); sub frobnicate { ... }
or when they are asked.
OUR @EXPORT_OK = qw( frobnicate barnicate ); sub barnicate { ... }
But you can also tell him to group things together, so your library user does not need to list all the methods. Consider this example.
package Foo; use Exporter; our @EXPORT_OK qw(monday tuesday wednesday thursday friday saturday sunday); sub monday { ... } sub tuesday { ... } sub wednesday { ... } sub thursday { ... } sub friday { ... } sub saturday { ... } sub sunday { ... }
Now, if I wanted all the working days, I would have to do this:
use Foo qw(monday tuesday wednesday thursday friday);
This one is a long line. Instead, it would be very useful if they could be grouped. Well, they can be. If you do this instead in your library:
package Foo; use Exporter; our %EXPORT_TAGS = ( working_days => [ qw(monday tuesday wednesday thursday friday) ], weekend_days => [ qw(saturday sunday) ] );
Then we can use it with one tag instead of five function names:
use Foo qw(:working_days);
Note that this is equivalent to:
use Foo ':working_days';
source share