Pattern/Atom.pm

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