GraphItems/Node.pm

filter: Statementstmt 29.1% 21 / 72 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 29.4% 5 / 17 Podpod 0.0% 0 / 3 totaltotal 23.0% 26 / 113 CC 12 SCAR 22.8
CC
12
Cov
24%
set_coords
30.0
move
12.0
_tie_coords
12.0
CRAP 9.8
« GraphItems/Examples/moving_items.pl ↑ Summary GraphItems/GraphItem.pm »
1 package Tk::GraphItems::Node;
2  
3  
4 # Copyright (C) 2007 by Christoph Lamprecht
5  
6 # This library is free software; you can redistribute it and/or modify
7 # it under the same terms as Perl itself, either Perl version 5.8.7 or,
8 # at your option, any later version of Perl 5 you may have available.
9  
10  
11  
12 5 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 our $VERSION = '0.11';
14  
15 #use Data::Dumper;
16 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 ▶use Scalar::Util (qw/looks_like_number/);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 5 require Tk::GraphItems::GraphItem;
21 5 require Tk::GraphItems::TiedCoord;
22 5 our @ISA = qw/ Tk::GraphItems::GraphItem /;
23  
24  
25 {
26 5 my %iinfo = (-text=>1); # item information hash
27  
28 0 ▶sub _set_canvas_bindings_for_tag{
Subroutine _set_canvas_bindings_for_tag: not called CC=1 SCAR=6.9
29 0 my ($self,$tag) = @_;
30 0 my $can = $self->{canvas};
31  
32 0 ▶ $can->bind($tag,'<1>' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
33 0 my($can) = @_;
34 0 my $e = $can->XEvent;
35 0 _items_start_drag ($can, $e->x, $e->y, \%iinfo);
36 }
37 0 );
38 0 ▶ $can->bind($tag,'<B1-Motion>' =>sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
39 0 _items_drag ($can,
40 $Tk::event->x,
41 $Tk::event->y,
42 \%iinfo);
43 }
44 0 );
45 }
46 } #end scope of iinfo
47  
48 5 ▶sub _items_drag {
Subroutine _items_drag: not called CC=1 SCAR=5.3
49 0 my($can, $x, $y, $iinfo) = @_;
50  
51 0 my $id= ($can->find(withtag => 'current'))[0];
52 0 my $self = _get_inst_by_id($can,$id);
53 0 my ($d_x,$d_y) = ($x-$iinfo->{lastX},$y-$iinfo->{lastY});
54 0 $self->_move($d_x ,$d_y);
55 0 $self->{was_dragged}=1;
56  
57 0 $iinfo->{lastX} = $x;
58 0 $iinfo->{lastY} = $y;
59  
60 } # end items_drag
61  
62 0 ▶sub _items_start_drag {
Subroutine _items_start_drag: not called CC=1 SCAR=6.9
63  
64 0 my($can, $x, $y, $iinfo) = @_;
65 0 $iinfo->{lastX} = $x;
66 0 $iinfo->{lastY} = $y;
67 0 my $id= ($can->find(withtag => 'current'))[0];
68 0 my $self = _get_inst_by_id($can,$id);
69 0 $self->{was_dragged}=0;
70  
71 } # end items_start_drag
72  
73  
74  
75 0 ▶sub move{
Subroutine move: not called CC=3 SCAR=24.8
Pod undocumented
76 0 my $self = shift;
77 looks_like_number($_)||
78 croak "method 'move' failed: args <$_[0]>,<$_[1]> have to be numbers!"
79 0 ▶ for (@_[0,1]);
Branch: 1 branch
BranchTrueFalseTotal
&looks_like_number($_) or croak("method 'move' failed: args <$_[0]>,<$_[1]> have to be numbers!") 0 0 0
80 0 $self->_move(@_);
81 }
82  
83 0 ▶sub _move{
Subroutine _move: not called CC=1 SCAR=6.9
84 0 my ($self,$d_x,$d_y) = @_;
85 0 my ($x,$y) = $self->get_coords;
86 0 $self->_set_coords($x+$d_x,$y+$d_y);
87 }
88 0 ▶sub set_coords{
Subroutine set_coords: not called CC=5 SCAR=34.0
Pod undocumented
89 0 my $self = shift;
90 0 ▶ if (ref $_[0]&& ref$_[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] and ref $_[1]) 0 0 0
Condition0%0/3
ref $_[0] and ref $_[1]
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_[0] and ref $_[1]
ref $_[0] ref $_[1]
Truth table0%0/3
A and B
A= ref $_[0]B= ref $_[1]
ABresult
0X0
100
111
91 0 $self->_tie_coords(@_);
92 0 return;
93 }
94 0 for ( @_[0,1] ) {
95 0 ▶ looks_like_number($_)||
Branch: 1 branch
BranchTrueFalseTotal
&looks_like_number($_) or croak("method 'set_coords' failed:\n" . "args <$_[0]>,<$_[1]> have to be numbers!") 0 0 0
96 croak "method 'set_coords' failed:\n"
97 ."args <$_[0]>,<$_[1]> have to be numbers!";
98 }
99 0 $self->_set_coords(@_);
100 }
101  
102 0 ▶sub _tie_coords{
Subroutine _tie_coords: not called CC=3 SCAR=24.8
103 0 my $self = shift;
104 0 $self ->_untie_coords;
105 0 ▶ tie ${$_[0]}, 'Tk::GraphItems::TiedCoord',$self,0 if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
106 0 ▶ tie ${$_[1]}, 'Tk::GraphItems::TiedCoord',$self,1 if ref $_[1];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[1] 0 0 0
107 0 @$self{qw/tiedx tiedy/}= @_[0,1];
108 }
109 0 ▶sub _untie_coords{
Subroutine _untie_coords: not called CC=2 SCAR=17.9
110 0 my $self = shift;
111 0 for (@$self{qw/tiedx tiedy/}) {
112 0 untie ${$_} ; #if tied $$_
113 }
114 }
115  
116 0 ▶sub was_dragged{
Subroutine was_dragged: not called CC=2 SCAR=17.9
Pod undocumented
117 0 my $self = shift;
118 0 ▶ return $self->{was_dragged} ||0;
Condition0%0/2
$self->{'was_dragged'} || 0
l!l
00
MC/DC0%0/1
$self->{'was_dragged'} || 0
$self->{'was_dragged'}
Truth table0%0/2
A
A= $self->{'was_dragged'}
Aresult
11
00
119 }
120  
121 0 ▶sub _get_inst_by_id{
Subroutine _get_inst_by_id: not called CC=2 SCAR=17.9
122 0 my ($can,$id) = @_;
123 0 my $obj_map = $can->{GraphItemsMap};
124 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
125 }
126  
127  
128  
129  
130 5 1;
131  
132 __END__
« GraphItems/Examples/moving_items.pl ↑ Summary GraphItems/GraphItem.pm »