[carton] 208/472: refactor with Package object
Lucas Kanashiro
kanashiro-guest at moszumanska.debian.org
Fri Jul 24 00:38:47 UTC 2015
This is an automated email from the git hooks/post-receive script.
kanashiro-guest pushed a commit to branch master
in repository carton.
commit 0ade6c2ed3a1f06fcf78a4d7c375e42920811c61
Author: Tatsuhiko Miyagawa <miyagawa at bulknews.net>
Date: Thu May 30 17:42:05 2013 +0900
refactor with Package object
---
lib/Carton/Lock.pm | 17 +++++++++++++----
lib/Carton/Package.pm | 19 +++++++++++++++++++
2 files changed, 32 insertions(+), 4 deletions(-)
diff --git a/lib/Carton/Lock.pm b/lib/Carton/Lock.pm
index 2c2dd47..896fde7 100644
--- a/lib/Carton/Lock.pm
+++ b/lib/Carton/Lock.pm
@@ -1,5 +1,6 @@
package Carton::Lock;
use strict;
+use Carton::Package;
sub new {
my($class, $data) = @_;
@@ -10,8 +11,8 @@ sub modules {
values %{$_[0]->{modules} || {}};
}
-sub write_mirror_index {
- my($self, $file) = @_;
+sub packages {
+ my $self = shift;
my $index;
while (my($name, $metadata) = each %{$self->{modules}}) {
@@ -23,9 +24,17 @@ sub write_mirror_index {
my @packages;
for my $package (sort keys %$index) {
my $module = $index->{$package};
- push @packages, [ $package, $module->{version}, $module->{meta}{pathname} ];
+ push @packages, Carton::Package->new($package, $module->{version}, $module->{meta}{pathname});
}
+ return @packages;
+}
+
+sub write_mirror_index {
+ my($self, $file) = @_;
+
+ my @packages = $self->packages;
+
open my $fh, ">", $file or die $!;
print $fh <<EOF;
File: 02packages.details.txt
@@ -39,7 +48,7 @@ Last-Updated: @{[ scalar localtime ]}
EOF
for my $p (@packages) {
- print $fh sprintf "%s %s %s\n", pad($p->[0], 32), pad($p->[1] || 'undef', 10, 1), $p->[2];
+ print $fh sprintf "%s %s %s\n", pad($p->name, 32), pad($p->version || 'undef', 10, 1), $p->pathname;
}
}
diff --git a/lib/Carton/Package.pm b/lib/Carton/Package.pm
new file mode 100644
index 0000000..cfa2b54
--- /dev/null
+++ b/lib/Carton/Package.pm
@@ -0,0 +1,19 @@
+package Carton::Package;
+use strict;
+
+sub new {
+ my($class, $name, $version, $pathname) = @_;
+ bless {
+ name => $name,
+ version => $version,
+ pathname => $pathname,
+ }, $class;
+}
+
+sub name { $_[0]->{name} }
+sub version { $_[0]->{version} }
+sub pathname { $_[0]->{pathname} }
+
+1;
+
+
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/carton.git
More information about the Pkg-perl-cvs-commits
mailing list