/usr/share/perl5/Padre/ProjectManager.pm is in padre 1.00+dfsg-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | package Padre::ProjectManager;
# Prototype for a full project manager abstraction to track projects open
# in Padre and provide a variety of utility functions.
use 5.008;
use strict;
use warnings;
use File::Spec ();
use Scalar::Util ();
use Padre::Project ();
our $VERSION = '1.00';
######################################################################
# Constructors
sub new {
my $class = shift;
my $self = bless {
# For now just store projects in the HASH directly
}, $class;
return $self;
}
sub project {
my $self = shift;
my $root = shift;
# Is this root an existing project?
if ( defined $self->{$root} ) {
return $self->{$root};
}
# Check for Dist::Zilla support
my $dist_ini = File::Spec->catfile( $root, 'dist.ini' );
if ( -f $dist_ini ) {
require Padre::Project::Perl::DZ;
return $self->{$root} = Padre::Project::Perl::DZ->new(
root => $root,
dist_ini => $dist_ini,
);
}
# Check for Module::Build support
my $build_pl = File::Spec->catfile( $root, 'Build.PL' );
if ( -f $build_pl ) {
require Padre::Project::Perl::MB;
return $self->{$root} = Padre::Project::Perl::MB->new(
root => $root,
build_pl => $build_pl,
);
}
# Check for ExtUtils::MakeMaker and Module::Install support
my $makefile_pl = File::Spec->catfile( $root, 'Makefile.PL' );
if ( -f $makefile_pl ) {
# Differentiate between Module::Install and ExtUtils::MakeMaker
if (0) {
require Padre::Project::Perl::MI;
return $self->{$root} = Padre::Project::Perl::MI->new(
root => $root,
makefile_pl => $makefile_pl,
);
} else {
require Padre::Project::Perl::EUMM;
return $self->{$root} = Padre::Project::Perl::EUMM->new(
root => $root,
makefile_pl => $makefile_pl,
);
}
}
# Check for an explicit vanilla project
my $padre_yml = File::Spec->catfile( $root, 'padre.yml' );
if ( -f $padre_yml ) {
return $self->{$root} = Padre::Project->new(
root => $root,
padre_yml => $padre_yml,
);
}
# Intuit a vanilla project based on a version control system
# checkout (that use a directory to indicate the root).
foreach my $vcs ( '.svn', '.git', '.hg', '.bzr' ) {
my $vcs_dir = File::Spec->catfile( $root, $vcs );
if ( -d $vcs_dir ) {
my $vcs_plugin = {
'.svn' => 'SVN',
'.git' => 'Git',
'.hg' => 'Mercurial',
'.bzr' => 'Bazaar',
}->{$vcs};
return $self->{$root} = Padre::Project->new(
root => $root,
vcs => $vcs_plugin,
);
}
}
# Intuit a vanilla project based on a CVS version control directory.
my $cvs_file = File::Spec->catfile( $root, 'CVS', 'Repository' );
if ( -f $cvs_file ) {
return $self->{$root} = Padre::Project->new(
root => $root,
vcs => 'CVS',
);
}
# No idea what this is, nothing probably
require Padre::Project::Null;
return $self->{$root} = Padre::Project::Null->new(
root => $root,
vcs => undef,
);
}
sub from_file {
my $self = shift;
my $file = shift;
# Split and scan
my ( $v, $d, $f ) = File::Spec->splitpath($file);
my @d = File::Spec->splitdir($d);
if ( defined $d[-1] and $d[-1] eq '' ) {
pop @d;
}
# Is the file inside a project we have loaded already.
# This should save a ton of filesystem calls when opening files.
foreach my $root ( sort keys %$self ) {
my $project = $self->{$root} or next;
# Skip baseline projects without a padre.yml file as we
# can't be confident enough that they are actually correct.
if ( Scalar::Util::blessed($project) eq 'Padre::Project' ) {
next unless $project->padre_yml;
}
# Split into parts (check volume before we bother to split dir)
my ( $pv, $pd, $pf ) = File::Spec->splitpath( $root, 1 );
if ( defined $v and defined $pv and $v ne $pv ) {
next;
}
my @pd = File::Spec->splitdir($pd);
if ( defined $pd[-1] and $pd[-1] eq '' ) {
pop @pd;
}
foreach my $n ( 0 .. $#pd ) {
last unless defined $d[$n];
last unless $d[$n] eq $pd[$n];
next unless $n == $#pd;
# Found a match, return the cached project
return $project;
}
}
foreach my $n ( reverse 0 .. $#d ) {
my $dir = File::Spec->catdir( @d[ 0 .. $n ] );
my $root = File::Spec->catpath( $v, $dir, '' );
# Check for Dist::Zilla support
my $dist_ini = File::Spec->catfile( $root, 'dist.ini' );
if ( -f $dist_ini ) {
require Padre::Project::Perl::DZ;
return $self->{$root} = Padre::Project::Perl::DZ->new(
root => $root,
dist_ini => $dist_ini,
);
}
# Check for Module::Build support
my $build_pl = File::Spec->catfile( $root, 'Build.PL' );
if ( -f $build_pl ) {
require Padre::Project::Perl::MB;
return $self->{$root} = Padre::Project::Perl::MB->new(
root => $root,
build_pl => $build_pl,
);
}
# Check for ExtUtils::MakeMaker and Module::Install support
my $makefile_pl = File::Spec->catfile( $root, 'Makefile.PL' );
if ( -f $makefile_pl ) {
# Differentiate between Module::Install and ExtUtils::MakeMaker
if (0) {
require Padre::Project::Perl::MI;
return $self->{$root} = Padre::Project::Perl::MI->new(
root => $root,
makefile_pl => $makefile_pl,
);
} else {
require Padre::Project::Perl::EUMM;
return $self->{$root} = Padre::Project::Perl::EUMM->new(
root => $root,
makefile_pl => $makefile_pl,
);
}
}
# Check for an explicit vanilla project
my $padre_yml = File::Spec->catfile( $root, 'padre.yml' );
if ( -f $padre_yml ) {
return $self->{$root} = Padre::Project->new(
root => $root,
padre_yml => $padre_yml,
);
}
# Intuit a vanilla project based on a git, mercurial or Bazaar
# checkout (that use a single directory to indicate the root).
foreach my $vcs ( '.git', '.hg', '.bzr' ) {
my $vcs_dir = File::Spec->catdir( $root, $vcs );
if ( -d $vcs_dir ) {
my $vcs_plugin = {
'.git' => 'Git',
'.hg' => 'Mercurial',
'.bzr' => 'Bazaar',
}->{$vcs};
return $self->{$root} = Padre::Project->new(
root => $root,
vcs => $vcs_plugin,
);
}
}
# Intuit a vanilla project based on a Subversion checkout
my $svn_dir = File::Spec->catdir( $root, '.svn' );
if ( -d $svn_dir ) {
# This must be the top-most .svn directory
if ($n) {
# We aren't at the top-most directory in the volume
my $updir = File::Spec->catdir( @d[ 0 .. $n - 1 ] );
my $svn_updir = File::Spec->catpath( $v, $updir, '.svn' );
unless ( -d $svn_dir ) {
return $self->{$root} = Padre::Project->new(
root => $root,
vcs => 'SVN',
);
}
}
}
# Intuit a vanilla project based on a CVS checkout
my $cvs_dir = File::Spec->catfile( $root, 'CVS', 'Repository' );
if ( -f $cvs_dir ) {
# This must be the top-most CVS directory
if ($n) {
# We aren't at the top-most directory in the volume
my $updir = File::Spec->catdir( @d[ 0 .. $n - 1 ] );
my $cvs_updir = File::Spec->catpath(
$v,
File::Spec->catdir( $updir, 'CVS' ),
'Repository',
);
unless ( -f $cvs_dir ) {
return $self->{$root} = Padre::Project->new(
root => $root,
vcs => 'CVS',
);
}
}
}
}
# This document is part of the null project
require Padre::Project::Null;
return Padre::Project::Null->new(
root => File::Spec->catpath( $v, File::Spec->catdir(@d), '' ),
vcs => undef,
);
}
sub from_document {
my $self = shift;
my $document = shift;
die "CODE INCOMPLETE";
}
######################################################################
# General Methods
sub project_exists {
defined $_[0]->{ $_[1] };
}
sub projects {
my $self = shift;
return map { $self->{$_} } sort keys %$self;
}
sub roots {
my $self = shift;
my @roots = sort keys %$self;
return @roots;
}
1;
# Copyright 2008-2013 The Padre development team as listed in Padre.pm.
# LICENSE
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl 5 itself.
|