View on
Tim Bunce > DashProfiler-1.13 > DashProfiler::Import



Annotate this POD


Open  0
View/Report Bugs
Module Version: 1.000045   Source  


DashProfiler::Import - Import curried DashProfiler sampler function at compile-time


  use DashProfiler::Import foo_profiler => [ "my context 1" ];

  use DashProfiler::Import foo_profiler => [ "my context 1" ],
                           bar_profiler => [ "my context 1", context2edit => sub { ... } ];

  use DashProfiler::Import -optional, baz_profiler => [ "my context 1" ];

  my $sample = foo_profiler("baz");


Firstly, read DashProfiler::UserGuide for a general introduction.

The example above imports a function called foo_profiler() that is a sample factory for the DashProfiler called "foo", pre-configured ("curried") to use the value "bar" for context1.

Using *_profiler_enabled()

It also imports a function called foo_profiler_enabled() that's a constant, returning false if the named DashProfiler was disabled at the time.

This is useful when profiling very time-senstive code and you want the profiling to have zero overhead when not in use. For example:

    my $sample = foo_profiler("baz") if foo_profiler_enabled();

Because the *_profiler_enabled function is a constant, the perl compiler will completely remove the code if the corresponding DashProfiler is disabled.

If there is no DashProfiler called "foo" then you'll get a compile-time error unless the -optional directive has been given first.

Generally this style of code in perl is considered bad practice and error prone:

    my $var = ... if ...;

because the behaviour when the condition is false on one execution having been true on previous execution is not well defined (on purpose, because it's surprisingly hard to explain what it does, and anyway, it may change).

For the DashProfiler::Import module, however, that style of code is just fine. That's because the condition is a compile-time constant.


DashProfiler by Tim Bunce, and


The DashProfiler distribution is Copyright (c) 2007-2008 Tim Bunce. Ireland. All rights reserved.

You may distribute under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file.

syntax highlighting: