GraphItems/GraphItem.pm

filter: Statementstmt 20.0% 16 / 80 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 26.3% 5 / 19 Podpod 0.0% 0 / 7 totaltotal 17.2% 21 / 122 CC 13 SCAR 19.7
CC
13
Cov
17%
new
12.0
_set_layer
12.0
_create_canvas_layers
12.0
CRAP 7.2
« GraphItems/Node.pm ↑ Summary GraphItems/TiedCoord.pm »
1 # Copyright (c) 2007 by Christoph Lamprecht. All rights reserved.
2 # This program is free software; you can redistribute it and/or
3 # modify it under the same terms as Perl itself.
4 # ch.l.ngre@online.de
5 package Tk::GraphItems::GraphItem;
6 5 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 5 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 our $VERSION = '0.12';
14  
15 0 ▶sub new{
Subroutine new: not called CC=3 SCAR=24.8
Pod undocumented
16 0 my $class = shift;
17 0 ▶ if (ref $class) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $class) 0 0 0
18 0 croak "new has to be called on a class-name!";
19 }
20 0 ▶ if (@_%2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ % 2) 0 0 0
21 0 croak "wrong number of args! ";
22 }
23 0 my $self = {};
24 0 bless $self, $class;
25 0 $self->initialize(@_);
26 0 return $self;
27 }
28 0 ▶sub initialize{
Subroutine initialize: not called CC=1 SCAR=6.9
Pod undocumented
29 0 my $self = shift;
30 0 $self->_register_instance;
31 0 return $self;
32 }
33  
34  
35 0 ▶sub add_dependent{
Subroutine add_dependent: not called CC=1 SCAR=6.9
Pod undocumented
36 0 my ($self,$dependent) = @_;
37 0 $self->{dependents}{$dependent} = $dependent;
38 }
39 0 ▶sub add_dependent_weak{
Subroutine add_dependent_weak: not called CC=1 SCAR=6.9
Pod undocumented
40 0 my ($self,$dependent) = @_;
41 0 $self->add_dependent($dependent);
42 0 weaken($self->{dependents}{$dependent});
43 }
44 0 ▶sub remove_dependent{
Subroutine remove_dependent: not called CC=1 SCAR=6.9
Pod undocumented
45 0 my ($self,$dependent) = @_;
46 0 delete $self->{dependents}{$dependent};
47 }
48  
49 0 ▶sub dependents{
Subroutine dependents: not called CC=1 SCAR=6.9
Pod undocumented
50 0 my $self = shift;
51 0 return values %{$self->{dependents}};
52 }
53  
54 0 ▶sub _set_layer{
Subroutine _set_layer: not called CC=3 SCAR=24.8
55 0 my ($self,$layer)=@_;
56 0 my $can = $self->get_canvas;
57  
58 0 my $l_id = $can->{GraphItem_layers}[$layer];
59 0 ▶ unless ($can->type($l_id)){
Branch: 1 branch
BranchTrueFalseTotal
unless ($can->type($l_id)) 0 0 0
60 0 croak "could not _set_layer.
61 Canvas-item with id <$l_id> has been deleted by user.
62 Be careful not to manipulate or delete Tk::GraphItems directly!" ;}
63 0 $can->lower($_,$l_id)for $self->canvas_items;
64 }
65  
66 0 ▶sub _create_canvas_layers{
Subroutine _create_canvas_layers: not called CC=3 SCAR=24.8
67 0 my $self = shift;
68 0 ▶ return if ($self->get_canvas)->{GraphItem_layers};
Branch: 1 branch
BranchTrueFalseTotal
if $self->get_canvas->{"GraphItem_layers"} 0 0 0
69 0 my $can = $self->get_canvas;
70 0 my @layers;
71 0 $layers[$_]= $can->createLine(10,10,10,10) for (0..2);
72 0 $can->{GraphItem_layers} = \@layers;
73 }
74  
75 0 ▶sub get_canvas{
Subroutine get_canvas: not called CC=1 SCAR=6.9
Pod undocumented
76 0 my $self = shift;
77 0 $self->{canvas};
78 }
79  
80 0 ▶sub _register_instance{
Subroutine _register_instance: not called CC=3 SCAR=24.8
81 0 my $self = shift;
82 0 my $can = $self->get_canvas;
83 0 ▶ my $obj_map = $can->{GraphItemsMap}||={};
Condition0%0/2
$can->{"GraphItemsMap"} ||= {}
l!l
00
MC/DC0%0/1
$can->{"GraphItemsMap"} ||= {}
$can->{"GraphItemsMap"}
Truth table0%0/2
A
A= $can->{"GraphItemsMap"}
Aresult
11
00
84 0 for ($self->canvas_items) {
85 0 $obj_map->{$_} = $self;
86 0 weaken ($obj_map->{$_});
87 }
88 }
89  
90 0 ▶sub _bind_this_class{
Subroutine _bind_this_class: not called CC=2 SCAR=17.9
91 0 my ($self,$event,$tag,$code) = @_;
92 0 my $can = $self->{canvas};
93 0 ▶ if ($code) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code) { } 0 0 0
94 0 ▶ $can->bind($tag,$event => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
95 0 my($can) = @_;
96 0 my $id= ($can->find(withtag => 'current'))[0];
97 0 my $self = _get_inst_by_id($can,$id);
98 0 $code->($self);
99 0 });
100 } else {
101 0 $can->bind( $tag,$event,'');
102 }
103 }
104  
105 0 ▶sub _get_inst_by_id{
Subroutine _get_inst_by_id: not called CC=2 SCAR=17.9
106 0 my ($can,$id) = @_;
107 0 my $obj_map = $can->{GraphItemsMap};
108 0 ▶ return $obj_map->{$id}||undef;
Condition0%0/2
$obj_map->{$id} || undef
l!l
00
MC/DC0%0/1
$obj_map->{$id} || undef
$obj_map->{$id}
Truth table0%0/2
A
A= $obj_map->{$id}
Aresult
11
00
109 }
110  
111  
112  
113 0 ▶sub DESTROY{
Subroutine DESTROY: not called CC=3 SCAR=24.8
114 0 my $self = shift;
115 0 my $can = $self->{canvas};
116 0 my $obj_map = $can->{GraphItemsMap};
117 #my $text = $self->text()||'a GraphItem';
118  
119 0 for ($self->canvas_items) {
120 0 eval{$can->delete($_)}; #if UNIVERSAL::isa($can,'Tk::Canvas');
121 0 delete $obj_map->{$_};
122 }
123 # destroy dependents...?
124 0 for ($self->dependents) {
125 0 eval{$_->destroy_myself}
126 }
127 #print "destroying $text\n";
128 }
129  
130  
131 5 1;
« GraphItems/Node.pm ↑ Summary GraphItems/TiedCoord.pm »