| 1 | package Perl::Metrics::Metric; | ||||||||||
| 2 | |||||||||||
| 3 | =pod | ||||||||||
| 4 | |||||||||||
| 5 | =head1 NAME | ||||||||||
| 6 | |||||||||||
| 7 | Perl::Metrics::Metric - A Perl Document Metric | ||||||||||
| 8 | |||||||||||
| 9 | =head1 DESCRIPTION | ||||||||||
| 10 | |||||||||||
| 11 | This class provides objects that represent a single metric on a single | ||||||||||
| 12 | document (although that document might actual exist as a number of | ||||||||||
| 13 | duplicate files in the index). | ||||||||||
| 14 | |||||||||||
| 15 | =head1 METHODS | ||||||||||
| 16 | |||||||||||
| 17 | In addition to the general methods provided by L<Class::DBI>, this class has | ||||||||||
| 18 | the following additional methods. | ||||||||||
| 19 | |||||||||||
| 20 | =cut | ||||||||||
| 21 | |||||||||||
| 22 | 6 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | 6 | ▶ | use Perl::Metrics (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | 6 | ▶ | use base 'Perl::Metrics::CDBI'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 25 | |||||||||||
| 26 | 6 | ▶ | use vars qw{$VERSION}; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 6 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | 6 | $VERSION = '0.09'; | |||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | =pod | ||||||||||
| 32 | |||||||||||
| 33 | =head2 hex_id | ||||||||||
| 34 | |||||||||||
| 35 | In the L<Perl::Metrics> system all documents are identified by the | ||||||||||
| 36 | hexidecimal MD5 value for their newline-localized contents. | ||||||||||
| 37 | |||||||||||
| 38 | The C<hex_id> accessor returns this id for the document that the metric | ||||||||||
| 39 | is for. | ||||||||||
| 40 | |||||||||||
| 41 | =head2 package | ||||||||||
| 42 | |||||||||||
| 43 | The C<package> returns a string which contains the class name of the metrics | ||||||||||
| 44 | package that generated the metric. | ||||||||||
| 45 | |||||||||||
| 46 | =head2 name | ||||||||||
| 47 | |||||||||||
| 48 | The C<name> accessor returns the name of the metric. | ||||||||||
| 49 | |||||||||||
| 50 | This name is package-specific. That is, a metric with a package of | ||||||||||
| 51 | 'Foo' and name 'some_metric' is different to a metric with package | ||||||||||
| 52 | 'Bar' and the same name 'some_metric'. | ||||||||||
| 53 | |||||||||||
| 54 | The metric name itself must be a valid Perl identifier. This test is | ||||||||||
| 55 | done using the C<_IDENTIFIER> function from L<Params::Util>. | ||||||||||
| 56 | |||||||||||
| 57 | =head2 version | ||||||||||
| 58 | |||||||||||
| 59 | In L<Perl::Metrics> some metrics packages will produce metrics that are | ||||||||||
| 60 | "version-unstable". In other words, if the metrics package is upgraded, | ||||||||||
| 61 | the metrics need to be recalculated. | ||||||||||
| 62 | |||||||||||
| 63 | The C<version> accessor returns the version of the metrics package at the | ||||||||||
| 64 | time the metric was calculated. | ||||||||||
| 65 | |||||||||||
| 66 | =head2 value | ||||||||||
| 67 | |||||||||||
| 68 | The C<value> accessor returns the value of the accessor. This could be | ||||||||||
| 69 | a number, word, or anything else. Please note that a value of C<undef>, | ||||||||||
| 70 | does B<not> mean the lack of a metric, but rather it means "unknown" | ||||||||||
| 71 | or "indeterminate" or has some other signficant meaning (in the context | ||||||||||
| 72 | of the metrics package). | ||||||||||
| 73 | |||||||||||
| 74 | =cut | ||||||||||
| 75 | |||||||||||
| 76 | 6 | Perl::Metrics::Metric->table( 'metrics' ); | |||||||||
| 77 | 6 | Perl::Metrics::Metric->columns( Primary => | |||||||||
| 78 | 'hex_id', # Document MD5 Identifier - 'abcdef1234567890' | ||||||||||
| 79 | 'package', # Metrics Package Class Name - 'Perl::Metrics::Plugin::Core' | ||||||||||
| 80 | 'name', # Package Metric Name - 'tokens' | ||||||||||
| 81 | ); | ||||||||||
| 82 | 6 | Perl::Metrics::Metric->columns( Essential => | |||||||||
| 83 | 'hex_id', | ||||||||||
| 84 | 'package', | ||||||||||
| 85 | 'name', | ||||||||||
| 86 | 'version', # Metrics Package Version - '1.04' | ||||||||||
| 87 | 'value', # Metric Value - '17', undef, 'Foo', '1.234' | ||||||||||
| 88 | ); | ||||||||||
| 89 | |||||||||||
| 90 | =pod | ||||||||||
| 91 | |||||||||||
| 92 | =head2 files @conditions | ||||||||||
| 93 | |||||||||||
| 94 | Because metrics are stored based on a document identifier rather than | ||||||||||
| 95 | by file name, if there are duplicate files indexed, one set of metrics | ||||||||||
| 96 | may related to more than one file. | ||||||||||
| 97 | |||||||||||
| 98 | The C<files> accessor searchs for all indexed C<::File> objects that have a | ||||||||||
| 99 | matching C<hex_id> to the C<::Metric> object. | ||||||||||
| 100 | |||||||||||
| 101 | =cut | ||||||||||
| 102 | |||||||||||
| 103 | 0 | ▶ | sub files { | ||||||||
|
Subroutine
files: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 104 | 0 | my $self = shift; | |||||||||
| 105 | |||||||||||
| 106 | # Apply default search options to those passed | ||||||||||
| 107 | 0 | my @params = ( hex_id => $self->hex_id, @_ ); | |||||||||
| 108 | 0 | ▶ | unless ( ref($params[-1]) eq 'HASH' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 109 | # Add standard ordering | ||||||||||
| 110 | 0 | push @params, { order_by => 'file' }; | |||||||||
| 111 | } | ||||||||||
| 112 | |||||||||||
| 113 | # Execute the search | ||||||||||
| 114 | 0 | Perl::Metrics::File->search( @params ); | |||||||||
| 115 | } | ||||||||||
| 116 | |||||||||||
| 117 | 6 | 1; | |||||||||
| 118 | |||||||||||
| 119 | =pod | ||||||||||
| 120 | |||||||||||
| 121 | =head1 SUPPORT | ||||||||||
| 122 | |||||||||||
| 123 | Bugs should be reported via the CPAN bug tracker at | ||||||||||
| 124 | |||||||||||
| 125 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Perl-Metrics> | ||||||||||
| 126 | |||||||||||
| 127 | For other issues, contact the author. | ||||||||||
| 128 | |||||||||||
| 129 | =head1 AUTHOR | ||||||||||
| 130 | |||||||||||
| 131 | Adam Kennedy E<lt>adamk@cpan.orgE<gt> | ||||||||||
| 132 | |||||||||||
| 133 | =head1 SEE ALSO | ||||||||||
| 134 | |||||||||||
| 135 | L<Perl::Metrics>, L<PPI> | ||||||||||
| 136 | |||||||||||
| 137 | =head1 COPYRIGHT | ||||||||||
| 138 | |||||||||||
| 139 | Copyright 2005 - 2008 Adam Kennedy. | ||||||||||
| 140 | |||||||||||
| 141 | This program is free software; you can redistribute | ||||||||||
| 142 | it and/or modify it under the same terms as Perl itself. | ||||||||||
| 143 | |||||||||||
| 144 | The full text of the license can be found in the | ||||||||||
| 145 | LICENSE file included with this module. | ||||||||||
| 146 | |||||||||||
| 147 | =cut | ||||||||||