Test-ModuleVersion
view release on metacpan or search on metacpan
lib/Test/ModuleVersion.pm view on Meta::CPAN
use 5.008007;
package Test::ModuleVersion;
our $VERSION = '0.17';
package
Test::ModuleVersion::Object::Simple;
our $VERSION = '3.0626';
use strict;
use warnings;
no warnings 'redefine';
use Carp ();
sub import {
my ($class, @methods) = @_;
# Caller
my $caller = caller;
# Base
if ((my $flag = $methods[0] || '') eq '-base') {
# Can haz?
no strict 'refs';
no warnings 'redefine';
*{"${caller}::has"} = sub { attr($caller, @_) };
# Inheritance
if (my $module = $methods[1]) {
$module =~ s/::|'/\//g;
require "$module.pm" unless $module->can('new');
push @{"${caller}::ISA"}, $module;
}
else {
push @{"${caller}::ISA"}, $class;
}
# strict!
strict->import;
warnings->import;
# Modern!
feature->import(':5.10') if $] >= 5.010;
}
# Method export
else {
# Exports
my %exports = map { $_ => 1 } qw/new attr class_attr dual_attr/;
# Export methods
foreach my $method (@methods) {
# Can be Exported?
Carp::croak("Cannot export '$method'.")
unless $exports{$method};
# Export
no strict 'refs';
*{"${caller}::$method"} = \&{"$method"};
}
}
}
sub new {
my $class = shift;
bless @_ ? @_ > 1 ? {@_} : {%{$_[0]}} : {}, ref $class || $class;
}
sub attr {
my ($self, @args) = @_;
my $class = ref $self || $self;
# Fix argument
unshift @args, (shift @args, undef) if @args % 2;
for (my $i = 0; $i < @args; $i += 2) {
# Attribute name
my $attrs = $args[$i];
$attrs = [$attrs] unless ref $attrs eq 'ARRAY';
# Default
my $default = $args[$i + 1];
foreach my $attr (@$attrs) {
Carp::croak("Default value of attr must be string or number " .
"or code reference (${class}::$attr)")
unless !ref $default || ref $default eq 'CODE';
# Code
my $code;
if (defined $default && ref $default) {
$code = sub {
( run in 0.635 second using v1.01-cache-2.11-cpan-39bf76dae61 )