| 1 | package Perl::Metrics::Plugin::MinimumVersion; | ||||||||||
| 2 | |||||||||||
| 3 | =pod | ||||||||||
| 4 | |||||||||||
| 5 | =head1 NAME | ||||||||||
| 6 | |||||||||||
| 7 | Perl::Metrics::Plugin::MinimumVersion - Perl::Metrics plugin for Perl::MinimumVersion | ||||||||||
| 8 | |||||||||||
| 9 | =head1 DESCRIPTION | ||||||||||
| 10 | |||||||||||
| 11 | This is a L<Perl::Metrics> "plugin" that generated the two primary metrics generated | ||||||||||
| 12 | by the L<Perl::MinimumVersion> module. These are the minimum explicit perl version | ||||||||||
| 13 | dependency, and the minimum syntax perl version dependency. | ||||||||||
| 14 | |||||||||||
| 15 | While this is an actual plugin to be used to real purposes, it provides a suitable | ||||||||||
| 16 | example of a simple plugin which brings functionality from a PPI-based module into | ||||||||||
| 17 | the larger L<Perl::Metrics> framework. | ||||||||||
| 18 | |||||||||||
| 19 | In addition, because the results could change based on changes to | ||||||||||
| 20 | L<Perl::MinimumVersion> this module also demonstrates the user of "versioned" metrics. | ||||||||||
| 21 | |||||||||||
| 22 | The C<metrics> method is overloaded to return an explicit list of metrics, with the | ||||||||||
| 23 | appropriate metric versions based on the version of L<Perl::MinimumVersion>. | ||||||||||
| 24 | |||||||||||
| 25 | =head1 METHODS | ||||||||||
| 26 | |||||||||||
| 27 | =cut | ||||||||||
| 28 | |||||||||||
| 29 | 2 | ▶ | use 5.006; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 31 | 2 | ▶ | use Carp (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 32 | 2 | ▶ | use version (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 33 | 2 | ▶ | use Perl::MinimumVersion 'PMV'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 34 | 2 | ▶ | use base 'Perl::Metrics::Plugin'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 35 | |||||||||||
| 36 | 2 | ▶ | use vars qw{$VERSION}; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 37 | 2 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 38 | 2 | $VERSION = '0.02'; | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | # The metrics are versioned, using the version of P:MV. | ||||||||||
| 42 | # This should cause the metrics to be automatically | ||||||||||
| 43 | # recalculated when P:MV is updated, without having | ||||||||||
| 44 | # to rerelease this dist as well. | ||||||||||
| 45 | 1 | ▶ | sub metrics { { | ||||||||
|
Subroutine
metrics: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 46 | 1 | explicit => $Perl::MinimumVersion::VERSION, | |||||||||
| 47 | syntax => $Perl::MinimumVersion::VERSION, | ||||||||||
| 48 | } } | ||||||||||
| 49 | |||||||||||
| 50 | =pod | ||||||||||
| 51 | |||||||||||
| 52 | =head2 metric_explicit | ||||||||||
| 53 | |||||||||||
| 54 | Provides the metric 'explicit', the minimum explicit version | ||||||||||
| 55 | provided as a normalized and serialized L<version> object. | ||||||||||
| 56 | |||||||||||
| 57 | =cut | ||||||||||
| 58 | |||||||||||
| 59 | 2 | ▶ | sub metric_explicit { | ||||||||
|
Subroutine
metric_explicit: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 60 | 2 | my ($self, $Document) = @_; | |||||||||
| 61 | 2 | ▶ | my $pmv = PMV->new($Document) or Carp::croak( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | "Failed to create Perl::MinimumVersion object for Document " | ||||||||||
| 63 | . $Document->hex_id | ||||||||||
| 64 | ); | ||||||||||
| 65 | 2 | my $version = $pmv->minimum_explicit_version; | |||||||||
| 66 | 2 | ▶ | return $version | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | ? $version->normal | ||||||||||
| 68 | : $version; | ||||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | =pod | ||||||||||
| 72 | |||||||||||
| 73 | =head2 metric_syntax | ||||||||||
| 74 | |||||||||||
| 75 | Provides the metric 'syntax', the minimum explicit version | ||||||||||
| 76 | provided as a normalized and serialized L<version> object. | ||||||||||
| 77 | |||||||||||
| 78 | =cut | ||||||||||
| 79 | |||||||||||
| 80 | 2 | ▶ | sub metric_syntax { | ||||||||
|
Subroutine
metric_syntax: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 81 | 2 | my ($self, $Document) = @_; | |||||||||
| 82 | 2 | ▶ | my $pmv = PMV->new($Document) or Carp::croak( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | "Failed to create Perl::MinimumVersion object for Document " | ||||||||||
| 84 | . $Document->hex_id | ||||||||||
| 85 | ); | ||||||||||
| 86 | 2 | my $version = $pmv->minimum_syntax_version; | |||||||||
| 87 | 2 | ▶ | return $version | ||||||||
|
Branch: 1 branch
| |||||||||||
| 88 | ? $version->normal | ||||||||||
| 89 | : $version; | ||||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | 2 | 1; | |||||||||
| 93 | |||||||||||
| 94 | =pod | ||||||||||
| 95 | |||||||||||
| 96 | =head1 SUPPORT | ||||||||||
| 97 | |||||||||||
| 98 | Bugs should be reported via the CPAN bug tracker at | ||||||||||
| 99 | |||||||||||
| 100 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Perl-Metrics-Plugin-MinimumVersion> | ||||||||||
| 101 | |||||||||||
| 102 | For other issues, contact the author. | ||||||||||
| 103 | |||||||||||
| 104 | =head1 AUTHOR | ||||||||||
| 105 | |||||||||||
| 106 | Adam Kennedy E<lt>adamk@cpan.orgE<gt> | ||||||||||
| 107 | |||||||||||
| 108 | =head1 SEE ALSO | ||||||||||
| 109 | |||||||||||
| 110 | L<Perl::Metrics::Plugin>, L<Perl::Metrics>, L<Perl::MinimumVersion>, | ||||||||||
| 111 | L<PPI> | ||||||||||
| 112 | |||||||||||
| 113 | =head1 COPYRIGHT | ||||||||||
| 114 | |||||||||||
| 115 | Copyright 2005 - 2008 Adam Kennedy. | ||||||||||
| 116 | |||||||||||
| 117 | This program is free software; you can redistribute | ||||||||||
| 118 | it and/or modify it under the same terms as Perl itself. | ||||||||||
| 119 | |||||||||||
| 120 | The full text of the license can be found in the | ||||||||||
| 121 | LICENSE file included with this module. | ||||||||||
| 122 | |||||||||||
| 123 | =cut | ||||||||||