File Coverage

blib/lib/Alien/CodePress.pm
Criterion Covered Total %
statement 90 97 92.7
branch 3 6 50.0
condition 1 3 33.3
subroutine 23 23 100.0
pod 8 8 100.0
total 125 137 91.2


line stmt bran cond sub pod time code
1             # $Id$
2             # $Source$
3             # $Author$
4             # $HeadURL$
5             # $Revision$
6             # $Date$
7             package Alien::CodePress;
8              
9 2     2   46906 use strict;
  2         3  
  2         72  
10 2     2   10 use warnings;
  2         4  
  2         50  
11 2     2   45 use 5.00600;
  2         8  
  2         65  
12              
13 2     2   19 use Carp;
  2         4  
  2         176  
14 2     2   10 use File::Spec;
  2         4  
  2         55  
15 2     2   1842 use File::Copy qw(copy);
  2         11148  
  2         145  
16 2     2   14 use File::Path qw(mkpath);
  2         3  
  2         102  
17 2     2   10 use File::Basename qw(dirname);
  2         4  
  2         149  
18 2     2   2345 use Archive::Extract;
  2         482118  
  2         106  
19 2     2   34 use vars qw($VERSION);
  2         4  
  2         114  
20              
21 2     2   1428 use Alien::CodePress::Archive;
  2         8  
  2         1048  
22              
23             $VERSION = 1.03;
24              
25             my @PROPERTIES = qw(
26             path
27             );
28              
29              
30             __PACKAGE__->make_accessors(@PROPERTIES);
31              
32              
33             sub new {
34 1     1 1 36 my ($class, $options_ref) = @_;
35 1         2 my $self = { };
36              
37 1         3 bless $self, $class;
38              
39 1         5 $self->init_properties();
40 1         4 $self->set_properties($options_ref);
41            
42 1         2 return $self;
43             }
44              
45             sub version {
46 1     1 1 395 return Alien::CodePress::Archive->version;
47             }
48              
49             sub files {
50 1     1 1 6 my ($self) = @_;
51 1         7 my $path = $self->get_path;
52 1         9 my $source = File::Spec->catfile(
53             $path,
54             Alien::CodePress::Archive->filename()
55             );
56              
57 1         12 my $ae = Archive::Extract->new( archive => $source );
58 1         380 my @file_list = $ae->files;
59              
60 1         15 return @file_list;
61             }
62              
63             sub install {
64 2     2 1 4011 my ($self, $destdir) = @_;
65 2         9 my $path = $self->get_path;
66 2   33     11 $destdir ||= File::Spec->curdir();
67              
68 2         36 my $source = File::Spec->catfile(
69             $path,
70             Alien::CodePress::Archive->filename()
71             );
72              
73 2         23 my $ae = Archive::Extract->new( archive => $source );
74 2         1626 $ae->extract( to => $destdir );
75            
76 2         46813 return;
77             }
78              
79             sub init_path {
80 1     1 1 2 my $module_filename = __PACKAGE__ . q{.pm};
81 1         5 $module_filename =~ s{::}{/}xmsg;
82 1         5 my $base = $INC{$module_filename};
83 1         5 $base =~ s{\.pm\z}{}xms;
84              
85 1         6 return $base;
86             }
87              
88              
89              
90             my %properties;
91             sub make_accessors {
92 2     2 1 7 my ($class, @properties) = @_;
93            
94 2         4 for my $property (@properties) {
95 2     2   12 no strict 'refs'; ## no critic
  2         4  
  2         980  
96 2         8 my $get_fqdn = join q{::}, $class, "get_$property";
97 2         4 my $set_fqdn = join q{::}, $class, "set_$property";
98 2         10 *{ $get_fqdn } = sub {
99 3     3   12 my ($self) = @_;
100 3         13 return $self->{$property};
101 2         10 };
102 2         10 *{ $set_fqdn } = sub {
103 1     1   2 my ($self, $value) = @_;
104 1         5 $self->{$property} = $value;
105 1         4 return;
106 2         7 };
107 2         9 $properties{$class}{$property} = 1;
108             }
109              
110 2         6 return;
111             }
112              
113             sub init_properties {
114 1     1 1 2 my ($self) = @_;
115              
116 1         2 for my $property (keys %{ $properties{ ref $self } }) {
  1         5  
117 1         3 my $init_property = "init_$property";
118 1         2 my $set_property = "set_$property";
119 1 50       11 if ($self->can($init_property)) {
120 1         6 $self->$set_property( $self->$init_property );
121             }
122             }
123              
124 1         2 return;
125             }
126              
127             sub set_properties {
128 1     1 1 2 my ($self, $properties_ref) = @_;
129 1 50       5 return if not ref $properties_ref eq 'HASH';
130            
131 0           while (my ($property, $value) = each %{ $properties_ref }) {
  0            
132 0           my $set_value = "set_$property";
133 0           $self->$set_value($value);
134             }
135              
136 0           return;
137             }
138              
139              
140             BEGIN {
141 2     2   5 my $this_module = __PACKAGE__;
142 2         15 $this_module =~ s{::}{/}xmsg;
143 2         7 $this_module = quotemeta $this_module;
144 2 50       112 if ( __FILE__ !~ m{$this_module\.pm \z}xms ) {
145 0         0 require Carp;
146 0         0 Carp::croak(sprintf
147             'Wrong case in name for module %s. ' .
148             'Sure you did not mean `use %s` instead?',
149             __PACKAGE__, __PACKAGE__
150             );
151             }
152             }
153              
154             1;
155              
156             __END__