blib/lib/Chemistry/Pattern/Bond.pm

filter: Statementstmt 95.0% 19 / 20 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 100% 2 / 2 totaltotal 93.5% 29 / 31 CC 3 SCAR 4.8
CC
3
Cov
92%
test
2.1
map_to
2.0
BEGIN
1.0
CRAP 1.6
« blib/lib/Parse/Yapp/Output.pm ↑ Summary Chemistry-Mol-0.35/t/zlib.t »
1 package Chemistry::Pattern::Bond;
2 10 $VERSION = '0.26';
3 # $Id: Bond.pm,v 1.10 2005/05/16 22:08:15 itubert Exp $
4  
5 =head1 NAME
6  
7 Chemistry::Pattern::Bond - A bond that knows how to match
8  
9 =head1 SYNOPSIS
10  
11 my $patt_bond = Chemistry::Pattern::Bond->new(order => 2);
12 $patt_bond->test_sub( sub {
13 my ($what, $where) = @_;
14 $where->type eq 'purple' ? 1 : 0; # only match purple bonds
15 });
16  
17 =head1 DESCRIPTION
18  
19 Objects of this class represent bonds in a pattern. This is a subclass of
20 Chemistry::Bond. In addition to the properties of regular bonds,
21 pattern bonds have a method for testing if they match an bond in a molecule.
22 By default, a pattern bond matches an bond if they have the same bond order.
23 It is possible to substitute this by an arbitrary criterion by providing
24 a custom test subroutine.
25  
26 =cut
27  
28 10 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 10 ▶use base qw(Chemistry::Bond);
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 =head1 METHODS
33  
34 =over 4
35  
36 =cut
37  
38 =item $patt_bond->test($bond)
39  
40 Tests if the pattern bond matches the bond given by $bond. Returns true or
41 false.
42  
43 =cut
44  
45 5132 ▶sub test {
Subroutine test: called CC=2 SCAR=7.6
Pod documented
46 5132 my ($what, $where) = @_;
47 5132 ▶ if ($what->test_sub) {
Branch: 1 branch
BranchTrueFalseTotal
if ($what->test_sub) { } 5132 0 5132
48 5132 return $what->test_sub->($what, $where);
49 } else {
50 0 return $what->order eq $where->order;
51 }
52 }
53  
54  
55  
56 =item $patt_bond->test_sub(\&my_test_sub)
57  
58 Specify an arbitrary test subroutine to be used instead of the default one.
59 &my_test_sub must take two parameters; the first one is the pattern bond
60 and the second is the bond to match. It must return true if there is a match.
61  
62 =cut
63  
64 10 Chemistry::Obj::accessor('test_sub');
65  
66 =item $patt_bond->map_to([$bond])
67  
68 Returns or sets the bond that is considered to be matched by $patt_bond.
69  
70 =cut
71  
72 #Chemistry::Obj::accessor('map_to');
73 14454 ▶sub map_to {
Subroutine map_to: called CC=2 SCAR=6.9
Pod documented
74 14454 my $self = shift;
75 14454 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 7964 6490 14454
76 #print "\t\tmapping $self to '@_'\n";
77 7964 ($self->{map_to}) = @_;
78 7964 $self;
79 } else {
80 #print "\t\t$self is mapped to '$self->{map_to}'\n";
81 6490 $self->{map_to};
82 }
83 }
84  
85 10 1;
86  
87 =back
88  
89 =head1 VERSION
90  
91 0.26
92  
93 =head1 SEE ALSO
94  
95 L<Chemistry::Pattern>
96  
97 The PerlMol website L<http://www.perlmol.org/>
98  
99 =head1 AUTHOR
100  
101 Ivan Tubert-Brohman E<lt>itub@cpan.orgE<gt>
102  
103 =head1 COPYRIGHT
104  
105 Copyright (c) 2005 Ivan Tubert-Brohman. All rights reserved. This program is
106 free software; you can redistribute it and/or modify it under the same terms as
107 Perl itself.
108  
109 =cut
110  
« blib/lib/Parse/Yapp/Output.pm ↑ Summary Chemistry-Mol-0.35/t/zlib.t »