]> git.vpit.fr Git - perl/modules/rgit.git/blob - lib/App/Rgit/Utils.pm
ee1fdd348014622aec683bd379cd034a4838c1f5
[perl/modules/rgit.git] / lib / App / Rgit / Utils.pm
1 package App::Rgit::Utils;
2
3 use strict;
4 use warnings;
5
6 use Cwd        (); # abs_path
7 use File::Spec (); # file_name_is_absolute, updir, splitdir, splitpath
8
9 =head1 NAME
10
11 App::Rgit::Utils - Miscellaneous utilities for App::Rgit classes.
12
13 =head1 VERSION
14
15 Version 0.08
16
17 =cut
18
19 our $VERSION = '0.08';
20
21 =head1 DESCRIPTION
22
23 Miscellaneous utilities for L<App::Rgit> classes.
24
25 This is an internal module to L<rgit>.
26
27 =head1 FUNCTIONS
28
29 =head2 C<abs_path>
30
31     my $absolute_path = abs_path($path);
32
33 Forcefully make a path C<$path> absolute (in L<Cwd/abs_path>'s meaning of the term) when it isn't already absolute or when it contains C<'..'>.
34
35 =cut
36
37 sub abs_path {
38  my ($path) = @_;
39
40  if (File::Spec->file_name_is_absolute($path)) {
41   my $updir  = File::Spec->updir;
42   my @chunks = File::Spec->splitdir((File::Spec->splitpath($path))[1]);
43
44   unless (grep $_ eq $updir, @chunks) {
45    return $path;
46   }
47  }
48
49  return Cwd::abs_path($path);
50 }
51
52 =head1 CONSTANTS
53
54 =head2 C<NEXT>
55
56 =head2 C<REDO>
57
58 =head2 C<LAST>
59
60 =head2 C<SAVE>
61
62 Codes to return from the C<report> callback to respectively proceed to the next repository, retry the current one, end it all, and save the return code.
63
64 =cut
65
66 use constant {
67  SAVE => 0x1,
68  NEXT => 0x2,
69  REDO => 0x4,
70  LAST => 0x8,
71 };
72
73 =head2 C<DIAG>
74
75 =head2 C<INFO>
76
77 =head2 C<WARN>
78
79 =head2 C<ERR>
80
81 =head2 C<CRIT>
82
83 Message levels.
84
85 =cut
86
87 use constant {
88  INFO => 3,
89  WARN => 2,
90  ERR  => 1,
91  CRIT => 0,
92 };
93
94 =head1 EXPORT
95
96 L<abs_path> is only exported on request.
97
98 C<NEXT> C<REDO>, C<LAST> and C<SAVE> are only exported on request, either by their name or by the C<'codes'> tags.
99
100 C<INFO>, C<WARN>, C<ERR> and C<CRIT> are only exported on request, either by their name or by the C<'levels'> tags.
101
102 =cut
103
104 use base qw/Exporter/;
105
106 our @EXPORT         = ();
107 our %EXPORT_TAGS    = (
108  funcs  => [ qw/abs_path/ ],
109  codes  => [ qw/SAVE NEXT REDO LAST/ ],
110  levels => [ qw/INFO WARN ERR CRIT/ ],
111 );
112 our @EXPORT_OK      = map { @$_ } values %EXPORT_TAGS;
113 $EXPORT_TAGS{'all'} = [ @EXPORT_OK ];
114
115 =head1 SEE ALSO
116
117 L<rgit>.
118
119 =head1 AUTHOR
120
121 Vincent Pit, C<< <perl at profvince.com> >>, L<http://profvince.com>.
122
123 You can contact me by mail or on C<irc.perl.org> (vincent).
124
125 =head1 BUGS
126
127 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>.
128 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
129
130 =head1 SUPPORT
131
132 You can find documentation for this module with the perldoc command.
133
134     perldoc App::Rgit::Utils
135
136 =head1 COPYRIGHT & LICENSE
137
138 Copyright 2008,2009,2010 Vincent Pit, all rights reserved.
139
140 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
141
142 =cut
143
144 1; # End of App::Rgit::Utils