File Coverage

blib/lib/Math/Symbolic/Custom/Base.pm
Criterion Covered Total %
statement 18 18 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 24 24 100.0


line stmt bran cond sub pod time code
1              
2             =encoding utf8
3              
4             =head1 NAME
5              
6             Math::Symbolic::Custom::Base - Base class for tree tests and transformations
7              
8             =head1 SYNOPSIS
9              
10             # Extending the Math::Symbolic::Custom class:
11             package Math::Symbolic::Custom::MyTransformations;
12             use Math::Symbolic::Custom::Base;
13             BEGIN {*import = \&Math::Symbolic::Custom::Base::aggregate_import}
14            
15             our $Aggregate_Export = [qw/apply_transformation1 .../];
16             sub apply_transformation1 {
17             # ...
18             }
19              
20             =head1 DESCRIPTION
21              
22             This is a base class for your extensions to the Math::Symbolic::Custom
23             class.
24              
25             To extend the class, just use the following template for your custom class:
26              
27             package Math::Symbolic::Custom::MyTransformations;
28              
29             use Math::Symbolic::Custom::Base;
30             BEGIN {*import = \&Math::Symbolic::Custom::Base::aggregate_import}
31            
32             our $Aggregate_Export = [...]; # exported subroutines listed here.
33            
34             # Now implement the subroutines.
35             # Exported subroutine names must start with 'apply_', 'mod_',
36             # 'is_', 'test_', 'contains_', or 'to_'
37            
38             # ...
39            
40             1;
41              
42             =head2 EXPORT
43              
44             Uses a custom exporter implementation to export certain routines from the
45             invoking namespace to the Math::Symbolic::Custom namespace.
46             But... Nevermind.
47              
48             =head1 SUBROUTINES
49              
50             =cut
51              
52             package Math::Symbolic::Custom::Base;
53              
54 23     23   455 use 5.006;
  23         91  
55 23     23   123 use strict;
  23         71  
  23         574  
56 23     23   112 use warnings;
  23         43  
  23         2713  
57              
58             our $VERSION = '0.613';
59             our $AUTOLOAD;
60              
61             =head2 aggregate_import
62              
63             aggregate_import() is the only public subroutine defined by
64             Math::Symbolic::Custom::Base and should only be called in BEGIN blocks like
65             the one shown in the SYNOPSIS above.
66              
67             =cut
68              
69             sub aggregate_import {
70 69     69 1 168 my $class = shift;
71 23     23   161 no strict 'refs';
  23         40  
  23         3874  
72 69         157 my $subs = ${"${class}::Aggregate_Export"};
  69         291  
73 69         225 foreach my $sub (@$subs) {
74 368         531 *{"Math::Symbolic::Custom::$sub"} = \&{"$class\:\:$sub"};
  368         4390  
  368         1019  
75             }
76             }
77              
78             1;
79             __END__