Commit 67440eee authored by Jonas Smedegaard's avatar Jonas Smedegaard
Browse files

use Object::Pad (not Class::Tiny)

parent dd67f459
[-Subroutines::ProhibitSubroutinePrototypes]
[TestingAndDebugging::RequireUseStrict]
equivalent_modules = Object::Pad
[PerlTidy]
[PerlTidySweet]
select = **/*.{pl,pm,t}
select = bin/*
argv = --profile=$ROOT/.perltidyrc
......
use strictures;
use feature 'signatures';
no warnings "experimental::signatures";
use Object::Pad 0.29;
=encoding UTF-8
......@@ -21,41 +19,56 @@ to represent an operating system distribution.
package App::DistroDelta::Distro 0.01;
use Log::Any ();
class App::DistroDelta::Distro;
use Class::Tiny
qw( name download_template homepage_template devpage_template ),
{
releases => sub { return {} },
log => sub { Log::Any->get_logger },
};
use Log::Any ();
use App::DistroDelta::DistroRelease;
sub add_release ( $self, %args )
has $name;
has $download_template;
has $homepage_template;
has $devpage_template;
has %releases;
has $log = Log::Any->get_logger;
BUILD(%opts) {
$name = $opts{name};
$download_template = $opts{download_template};
$homepage_template = $opts{homepage_template};
$devpage_template = $opts{devpage_template};
}
# slot methods
# TODO: use :reader attribute on slot instead, when perltidy supports it
method download_template { return $download_template }
method homepage_template { return $homepage_template }
method devpage_template { return $devpage_template }
method add_release (%args)
{
my $rel_name = $args{name};
my $rel;
# create and register distro release, or reuse existing
if ( exists $self->{releases}{$rel_name} ) {
$rel = $self->{releases}{$rel_name};
if ( exists $releases{$rel_name} ) {
$rel = $releases{$rel_name};
if ( $self->log->is_debug ) {
$self->log->debug( "reuse release:", $rel_name,
{ distro => $self->{name} } );
if ( $log->is_debug ) {
$log->debug( "reuse release:", $rel_name,
{ distro => $name } );
}
}
else {
$rel = App::DistroDelta::DistroRelease->new( distro => $self, %args );
if ( $self->log->is_debug ) {
$self->log->debug( "add release:", $rel_name,
{ distro => $self->{name} } );
if ( $log->is_debug ) {
$log->debug( "add release:", $rel_name,
{ distro => $name } );
}
# register distro release
$self->{releases}{$rel_name} = $rel;
$releases{$rel_name} = $rel;
}
}
......
use strictures;
use feature 'signatures';
no warnings "experimental::signatures";
use Object::Pad 0.29;
=encoding UTF-8
......@@ -22,69 +20,9 @@ of an operating system distribution.
package App::DistroDelta::DistroRelease 0.01;
use Log::Any ();
sub sources ( $self, @types )
{
return ()
unless $self->{sources};
return @{ $self->{sources} }
unless @types;
@_ = ();
for my $src ( @{ $self->{sources} } ) {
push @_, grep { $src->type eq $_ } @types;
}
return @_;
}
sub source_times ($self)
{
$self->update_sources;
return @{ $self->{source_times} };
}
sub bases ( $self, @bases )
{
if (@bases) {
$self->{bases} = [@bases];
return (@bases);
}
return ( $self->{bases} ? @{ $self->{bases} } : () );
}
sub parents ( $self, @parents )
{
if (@parents) {
$self->{parents} = [@parents];
return (@parents);
}
return ( $self->{parents} ? @{ $self->{parents} } : () );
}
sub origins ( $self )
{
return map { $self->{$_} ? @{ $self->{$_} } : () } qw(bases parents);
}
class App::DistroDelta::DistroRelease;
use Class::Tiny qw( name distro sources source_times bases parents origins ),
{
packages => sub { return {} },
package_releases => sub { return {} },
download_processor => sub {
return URI::Template->new( $_[0]->distro->{download_template} );
},
homepage_processor => sub {
return URI::Template->new( $_[0]->distro->{homepage_template} );
},
devpage_processor => sub {
return URI::Template->new( $_[0]->distro->{devpage_template} );
},
log => sub { Log::Any->get_logger },
};
use Log::Any ();
use URI::Template;
use Dpkg::Version;
......@@ -94,21 +32,38 @@ use App::DistroDelta::DateTime;
use App::DistroDelta::Package;
use App::DistroDelta::PackageRelease;
has $name;
has $distro;
has @lists;
has @sources;
has @source_times;
has @bases;
has @parents;
has @origins;
has $download_processor;
has $homepage_processor;
has $devpage_processor;
has %packages;
has %package_releases;
has $log = Log::Any->get_logger;
my $RE_lists
= qr/^(deb-src)(?:\s+\[\s*([^\[\]]+?)\s*\])?\s+(\S+)\s+(\S+)(\s+\S+)+/;
my $RE_pkg_dirstem = qr/^((?:lib)?.)/;
sub BUILD ( $self, $args )
{
$self->log->context->{release} = $self->{name};
BUILD(%opts) {
$name = $opts{name};
$distro = $opts{distro};
@lists = @{ $opts{lists} };
$log->context->{release} = $name;
if ( $args->{lists} ) {
@_ = ();
for ( @{ $args->{lists} } ) {
if ( $opts{lists} ) {
for ( @{ $opts{lists} } ) {
my ( $type, $options, $base_uri, $suite, $components )
= $_ =~ /$RE_lists/;
for my $component ( split( ' ', $components ) ) {
push @_, App::DistroDelta::DistroSource->new(
push @sources, App::DistroDelta::DistroSource->new(
release => $self,
type => $type,
options => $options,
......@@ -119,18 +74,49 @@ sub BUILD ( $self, $args )
}
}
if ( $self->log->is_debug ) {
$self->log->debug( "resolved sources:", scalar @_ );
if ( $log->is_debug ) {
$log->debug( "resolved sources:", scalar @sources );
}
$self->{sources} = [@_];
}
@bases = @{ $opts{bases} }
if $opts{bases};
@parents = @{ $opts{parents} }
if $opts{parents};
$download_processor = URI::Template->new( $distro->download_template )
if $distro->download_template;
$homepage_processor = URI::Template->new( $distro->homepage_template )
if $distro->homepage_template;
$devpage_processor = URI::Template->new( $distro->devpage_template )
if $distro->devpage_template;
}
return $self;
# slot methods
# TODO: use :reader attribute on slot instead, when perltidy supports it
method name { return $name }
method bases (@new) { return @new ? @bases = @new : @bases }
method parents (@new) { return @new ? @parents = @new : @parents }
method origins { return @bases, @parents }
method sources (@types)
{
return ()
unless @sources;
return @sources
unless @types;
@_ = ();
for my $src (@sources) {
push @_, grep { $src->type eq $_ } @types;
}
return @_;
}
sub update_sources ($self)
method update_sources ()
{
return 0 if $self->{source_times};
return 0 if @source_times;
my @origins = $self->origins;
my ( @mod, @upd );
......@@ -147,67 +133,71 @@ sub update_sources ($self)
push @mod, $src->modified || ();
}
$self->{source_times} = [
@source_times = (
( sort @mod )[ 0, $#mod ],
( sort @upd )[ 0, $#upd ],
];
);
return 1;
}
sub get_package ( $self, $pkg_name )
method source_times () { $self->update_sources; return @source_times }
method get_package ($pkg_name)
{
# return unless exists $package_releases{$pkg_name};
$self->update_sources;
if ( !exists $self->{packages}{$pkg_name} ) {
if ( !exists $packages{$pkg_name} ) {
for ( $self->origins ) {
$self->{packages}{$pkg_name} = $_->get_package($pkg_name);
$packages{$pkg_name} = $_->get_package($pkg_name);
last;
}
$self->{packages}{$pkg_name}
$packages{$pkg_name}
//= App::DistroDelta::Package->new( name => $pkg_name );
}
return $self->{packages}{$pkg_name};
return $packages{$pkg_name};
}
sub get_package_release_versions ( $self, $pkg_name )
method get_package_release_versions ($pkg_name)
{
return unless exists $self->{package_releases}{$pkg_name};
return unless exists $package_releases{$pkg_name};
$self->{package_releases}{$pkg_name}{versions} //= [
$package_releases{$pkg_name}{versions} //= [
sort { version_compare( $b, $a ) }
keys %{ $self->{package_releases}{$pkg_name}{args} }
keys %{ $package_releases{$pkg_name}{args} }
];
return wantarray
? @{ $self->{package_releases}{$pkg_name}{versions} }
: ${ $self->{package_releases}{$pkg_name}{versions} }[0];
? @{ $package_releases{$pkg_name}{versions} }
: ${ $package_releases{$pkg_name}{versions} }[0];
}
sub get_package_releases ( $self, $pkg_name )
method get_package_releases ($pkg_name)
{
return unless exists $self->{package_releases}{$pkg_name};
return unless exists $package_releases{$pkg_name};
@_ = ();
for ( $self->get_package_release_versions($pkg_name) ) {
$self->get_package($pkg_name)
unless exists $self->{packages}{$pkg_name};
$self->{package_releases}{$pkg_name}{obj}{$_}
= $self->{packages}{$pkg_name}->add_release(
sources => $self->{package_releases}{$pkg_name}{sources}{$_},
%{ $self->{package_releases}{$pkg_name}{args}{$_} },
) unless exists $self->{package_releases}{$pkg_name}{obj}{$_};
return $self->{package_releases}{$pkg_name}{obj}{$_}
unless exists $packages{$pkg_name};
$package_releases{$pkg_name}{obj}{$_}
= $packages{$pkg_name}->add_release(
sources => $package_releases{$pkg_name}{sources}{$_},
%{ $package_releases{$pkg_name}{args}{$_} },
) unless exists $package_releases{$pkg_name}{obj}{$_};
return $package_releases{$pkg_name}{obj}{$_}
unless wantarray;
push @_, $self->{package_releases}{$pkg_name}{obj}{$_};
push @_, $package_releases{$pkg_name}{obj}{$_};
}
return @_;
}
sub add_package_release ( $self, %args )
method add_package_release (%args)
{
my ( $src, $pkg_name, $pkg, $pkgrel, $version );
......@@ -217,16 +207,16 @@ sub add_package_release ( $self, %args )
delete $args{source};
delete $args{name};
$self->{package_releases}{$pkg_name}{args}{$version} = {
$package_releases{$pkg_name}{args}{$version} = {
project => $pkg,
%args,
};
push @{ $self->{package_releases}{$pkg_name}{sources}{$version} }, $src;
push @{ $package_releases{$pkg_name}{sources}{$version} }, $src;
}
sub pkgnames ( $self, @pkg_names )
method pkgnames (@pkg_names)
{
$self->log->context->{release} = $self->{name};
$log->context->{release} = $name;
my $filter = { map { $_ => undef } @pkg_names };
......@@ -234,22 +224,22 @@ sub pkgnames ( $self, @pkg_names )
@_
= (@pkg_names)
? grep { exists $filter->{$_} } keys %{ $self->{package_releases} }
: keys %{ $self->{package_releases} };
? grep { exists $filter->{$_} } keys %package_releases
: keys %package_releases;
if ( $self->log->is_trace ) {
$self->log->trace( "resolved pkgnames:", @_ );
if ( $log->is_trace ) {
$log->trace( "resolved pkgnames:", @_ );
}
elsif ( $self->log->is_debug ) {
$self->log->debug( "resolved pkgnames:", scalar @_ );
elsif ( $log->is_debug ) {
$log->debug( "resolved pkgnames:", scalar @_ );
}
return @_;
}
sub pkgnames_with_version ( $self, @pkg_names )
method pkgnames_with_version (@pkg_names)
{
$self->log->context->{release} = $self->{name};
$log->context->{release} = $name;
@_ = ();
for my $pkg_name ( $self->pkgnames(@pkg_names) ) {
......@@ -258,17 +248,17 @@ sub pkgnames_with_version ( $self, @pkg_names )
push @_, "$pkg_name $version";
}
if ( $self->log->is_trace ) {
$self->log->trace( "resolved pkgnames_with_version:", @_ );
if ( $log->is_trace ) {
$log->trace( "resolved pkgnames_with_version:", @_ );
}
elsif ( $self->log->is_debug ) {
$self->log->debug( "resolved pkgnames_with_version:", scalar @_ );
elsif ( $log->is_debug ) {
$log->debug( "resolved pkgnames_with_version:", scalar @_ );
}
return @_;
}
sub as_pkg_strings ( $self, @pkgs )
method as_pkg_strings (@pkgs)
{
@_ = ();
for my $pkg (@pkgs) {
......@@ -289,12 +279,12 @@ sub as_pkg_strings ( $self, @pkgs )
component => $src->component,
suite => $src->suite,
);
$download = $self->download_processor->process_to_string(%args)
if $self->download_processor;
$homepage = $self->homepage_processor->process_to_string(%args)
if $self->homepage_processor;
$devpage = $self->devpage_processor->process_to_string(%args)
if $self->devpage_processor;
$download = $download_processor->process_to_string(%args)
if $download_processor;
$homepage = $homepage_processor->process_to_string(%args)
if $homepage_processor;
$devpage = $devpage_processor->process_to_string(%args)
if $devpage_processor;
}
push @_, {
......
use strictures;
use feature 'signatures';
no warnings "experimental::signatures";
use Object::Pad 0.29;
=encoding UTF-8
......@@ -22,24 +20,21 @@ between releases of one or more operating system distributions.
package App::DistroDelta::DistroReleaseComparison 0.01;
sub template_processor ($self)
{
Text::Xslate->new(
path => $self->{templates},
syntax => 'TTerse',
type => 'text',
);
}
use Class::Tiny qw( releases suffix lists templates ), {
reasons => sub { return {} },
log => sub { Log::Any->get_logger },
};
class App::DistroDelta::DistroReleaseComparison;
use Text::Xslate;
use Set::Object qw(set);
use Log::Any ();
has @releases;
has $suffix;
has %lists;
has %templates;
has %reasons;
has $template_processor;
has $log = Log::Any->get_logger;
my @additions = qw(new local);
my @forks
= qw(ahead backport sideport feature antifeature localfeature clogged clash);
......@@ -144,13 +139,17 @@ my %strings = (
my $RE_pkg = qr/^([a-z0-9]\S*)/m;
sub BUILD ( $self, $args )
{
my @releases = @{ $self->{releases} };
BUILD(%args) {
@releases = @{ $args{releases} };
$suffix = $args{suffix};
%lists = %{ $args{lists} };
%templates = %{ $args{templates} };
my $suffix = $args->{suffix};
my %lists = %{ $args->{lists} };
my %reasons;
$template_processor = Text::Xslate->new(
path => \%templates,
syntax => 'TTerse',
type => 'text',
);
my $release = $releases[0];
my @others = @releases[ 1 .. $#releases ];
......@@ -166,10 +165,10 @@ sub BUILD ( $self, $args )
my $forked = $versions->difference($otherversions);
my $added = $names->difference($othernames);
if ( $self->log->is_trace() ) {
$self->log->trace( "removed:", $removed->members );
$self->log->trace( "forked:", $forked->members );
$self->log->trace( "added:", $added->members );
if ( $log->is_trace() ) {
$log->trace( "removed:", $removed->members );
$log->trace( "forked:", $forked->members );
$log->trace( "added:", $added->members );
}
my $localban = $removed->intersection( set @{ $lists{banned} } );
......@@ -195,20 +194,13 @@ sub BUILD ( $self, $args )
set @{ $reasons{new} },
@{ $reasons{local} },
);
$self->{reasons} = \%reasons;
return $self;
}
sub as_html ( $self )
method as_html ()
{
my @releases = @{ $self->{releases} };
my %reasons = %{ $self->{reasons} };
my ( @modified, @updated, %vars );
my $release = $releases[0];
my @others = @releases[ 1 .. $#releases ];
my ( @modified, @updated, %vars );
for (@releases) {
my @times = $_->source_times;
......@@ -219,11 +211,11 @@ sub as_html ( $self )
my @mod = ( sort @modified );
my @upd = ( sort @updated );
$self->log->context->{release} = $release->name;
$log->context->{release} = $release->name;
%vars = (
release => $release,
suffix => $self->{suffix},
suffix => $suffix,
other_releases => [@others],
datetime_pkgmod_start => $mod[0]->rfc3339,
timestamp_pkgmod_start => $mod[0]->as_human_string,
......@@ -247,7 +239,7 @@ sub as_html ( $self )
}
push @pkgs, $pkg;
push @pkgs_content,
$self->template_processor->render(
$template_processor->render(
'package',
$release->as_pkg_strings($pkg)
);
......@@ -261,7 +253,7 @@ sub as_html ( $self )
};
}
}
return $self->template_processor->render( 'release', \%vars );
return $template_processor->render( 'release', \%vars );
}
1;
......
use strictures;
use feature 'signatures';
no warnings "experimental::signatures";
use Object::Pad 0.29;
=encoding UTF-8
......@@ -22,15 +20,9 @@ for a specific release of an operating system distribution.