]> git.vpit.fr Git - perl/modules/rgit.git/blob - lib/App/Rgit/Config.pm
If everything fails, try to append '.bat' to the git executable on win32
[perl/modules/rgit.git] / lib / App / Rgit / Config.pm
1 package App::Rgit::Config;
2
3 use strict;
4 use warnings;
5
6 use Carp qw/croak/;
7 use Cwd qw/abs_path/;
8 use File::Spec::Functions qw/file_name_is_absolute/;
9
10 use Object::Tiny qw/root git cwd_repo debug/;
11
12 use App::Rgit::Repository;
13 use App::Rgit::Utils qw/validate :levels/;
14
15 use constant IS_WIN32 => $^O eq 'MSWin32';
16
17 =head1 NAME
18
19 App::Rgit::Config - Base class for App::Rgit configurations.
20
21 =head1 VERSION
22
23 Version 0.05
24
25 =cut
26
27 our $VERSION = '0.05';
28
29 =head1 DESCRIPTION
30
31 Base class for L<App::Rgit> configurations.
32
33 This is an internal class to L<rgit>.
34
35 =head1 METHODS
36
37 =head2 C<< new root => $root, git => $git >>
38
39 Creates a new configuration object based on the root directory C<$root> and using C<$git> as F<git> executable.
40
41 =cut
42
43 sub new {
44  my ($class, %args) = &validate;
45
46  my $root = $args{root};
47  return unless defined $root and -d $root;
48  $root = abs_path $root unless file_name_is_absolute $root;
49
50  my $git = $args{git};
51  return unless defined $git;
52  if (IS_WIN32) {
53   unless (-x $git) {
54    $git .= '.bat';
55    return unless -x $git;
56   }
57  } else {
58   return unless -x $git;
59  }
60
61  my $conf = 'App::Rgit::Config::Default';
62  eval "require $conf; 1" or croak "Couldn't load $conf: $@";
63
64  my $r = App::Rgit::Repository->new(fake => 1);
65  return unless defined $r;
66
67  $conf->SUPER::new(
68   root     => $root,
69   git      => $git,
70   cwd_repo => $r,
71   debug    => defined $args{debug} ? int $args{debug} : WARN,
72  );
73 }
74
75 =head2 C<info $msg>
76
77 =head2 C<warn $msg>
78
79 =head2 C<err $msg>
80
81 =head2 C<crit $msg>
82
83 Notifies a message C<$msg> of the corresponding level.
84
85 =cut
86
87 sub _notify {
88  my $self = shift;
89  my $level = shift;
90  if ($self->debug >= $level) {
91   print STDERR @_;
92   return 1;
93  }
94  return 0;
95 }
96
97 sub info { shift->_notify(INFO, @_) }
98
99 sub warn { shift->_notify(WARN, @_) }
100
101 sub err  { shift->_notify(ERR, @_) }
102
103 sub crit { shift->_notify(CRIT, @_) }
104
105 =head2 C<root>
106
107 =head2 C<git>
108
109 =head2 C<repos>
110
111 =head2 C<cwd_repo>
112
113 =head2 C<debug>
114
115 Accessors.
116
117 =head1 SEE ALSO
118
119 L<rgit>.
120
121 =head1 AUTHOR
122
123 Vincent Pit, C<< <perl at profvince.com> >>, L<http://profvince.com>.
124    
125 You can contact me by mail or on C<irc.perl.org> (vincent).
126
127 =head1 BUGS
128
129 Please report any bugs or feature requests to C<bug-rgit at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=rgit>.  I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
130
131 =head1 SUPPORT
132
133 You can find documentation for this module with the perldoc command.
134
135     perldoc App::Rgit::Config
136
137 =head1 COPYRIGHT & LICENSE
138
139 Copyright 2008 Vincent Pit, all rights reserved.
140
141 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
142
143 =cut
144
145 1; # End of App::Rgit::Config