blib/lib/GD/Graph/Hooks.pm

filter: Statementstmt 77.7% 7 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 83.3% 10 / 12 CC 1 SCAR 0.9
CC
1
Cov
78%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
↑ Summary
1  
2 package GD::Graph::Hooks;
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 0 ▶use GD::Graph::axestype;
Subroutine BEGIN: called CC=1 SCAR=2.6
7 use constant {
8 POST_INIT => 0,
9 PRE_TEXT => 0,
10  
11 POST_TEXT => 1,
12 PRE_AXIS => 1,
13  
14 POST_AXIS => 2,
15 PRE_DATA => 2,
16  
17 POST_DATA => 3,
18 PRE_VALUES => 3,
19  
20 POST_VALUES => 4,
21 PRE_LEGEND => 4,
22  
23 POST_LEGEND => 5,
24 PRE_RETURN => 5,
25 };
26  
27 sub validate {
28 my $slot = shift;
29 $slot >= 0 and $slot <= 5;
30 }
31  
32 our $VERSION = "1.0003";
33  
34 {
35 no warnings; # hackery below, no warnings in here thanks
36  
37 *GD::Graph::axestype::add_hook = sub {
38 my $this = shift;
39 my $slot = int shift; croak "slot unknown" unless validate($slot);
40 my $code = shift;
41 my $hook = ref($code) eq "CODE" ? $code : sub { eval $code };
42  
43 push @{$this->{_hooks}{$slot}}, $hook;
44 };
45  
46 *GD::Graph::axestype::call_hooks = sub {
47 my $this = shift;
48 my $slot = shift;
49  
50 return unless exists $this->{_hooks}{$slot};
51  
52 for my $f (@{$this->{_hooks}{$slot}}) {
53 $f->( $this, @$this{qw(graph left right top bottom gdta_x_axis gdta_y_axis)} );
54 }
55 };
56  
57 *GD::Graph::axestype::plot = sub {
58 my $self = shift;
59 my $data = shift;
60  
61 $self->check_data($data) or return;
62 $self->init_graph() or return;
63 $self->setup_text() or return;
64 $self->setup_legend();
65 $self->setup_coords() or return;
66 $self->call_hooks(POST_INIT);
67 $self->draw_text();
68 $self->call_hooks(POST_TEXT);
69 unless (defined $self->{no_axes}) {
70 $self->draw_axes();
71 $self->draw_ticks() or return;
72 }
73 $self->call_hooks(POST_AXIS);
74 $self->draw_data() or return;
75 $self->call_hooks(POST_DATA);
76 $self->draw_values() or return;
77 $self->call_hooks(POST_VALUES);
78 $self->draw_legend();
79 $self->call_hooks(POST_LEGEND);
80  
81 return $self->{graph}
82 };
83 }
84  
85 1;
86  
87 __END__
↑ Summary