| Arch::Name(3pm) | User Contributed Perl Documentation | Arch::Name(3pm) |
Arch::Name - parse, store and construct an arch name
use Arch::Name;
my $version_spec = 'some@hacker.org--pub/bugzilla--main--1.2';
my $name = Arch::Name->new($version_spec);
die unless $name eq $version;
die unless $name - 2 eq 'some@hacker.org--pub/bugzilla';
die unless $name->branch eq 'main';
# list other branches (latest versions) in the tree archive
my $category = Arch::Name->new($tree->get_version)->go_up(2);
foreach my $branch_str ($session->branches($category)) {
my $branch = $category->child($branch_str);
my $latest_version = ($session->versions($branch))[-1];
print $branch->go_down($latest_version)->to_string, "\n";
}
# another way to manipulate it
my $category = Arch::Name->new($tree->get_version);
$category->apply([undef, undef]);
print $category->fqn, "\n", $category->parent->to_hash, "\n";
# validate arch name from the user input
# suppose we write a tool that accepts 3 command line args:
# * tree directory or branch+ (to get tree)
# * fully qualified revision (to get changeset)
# * archive+ (fully qualified category is ok too)
my ($name_or_dir, $rvsn, $archv) = @ARGV;
my $tree = Arch::Name->is_valid($name_or_dir, "branch+")?
Arch::Session->new->get_tree($name_or_dir):
Arch::Tree->new($name_or_dir);
my $cset = $session->get_revision_changeset($rvsn)
if Arch::Name->is_valid($rvsn, 'revision');
my $possibly_archive = Arch::Name->new($archv);
die "No archive" unless $possibly_archive->is_valid;
my $archive = $possibly_archive->cast('archive');
This class represents the Arch name concept and provides useful methods to manipulate it.
The fully qualified Arch name looks like archive/category--branch--version--revision for revisions and some prefix of it for other hierarchy citizens. The branchless names have "--branch" part removed.
The following class methods are available:
new, set, clone, apply, go_up, go_down, parent, child, to_string, to_nonarch_string, to_array, to_hash, fqn, nan, get, archive, category, branch, version, revision, error, level, cast, is_valid.
By default (without init), the empty name is created that does not pass is_valid check.
If on_error is set and positive, then die on any initialization error, i.e. when only a partial name is parsed or no name components are given. By default an object representing a partial name is returning, and error may be used. If on_error is set and is negative, then don't set any error.
Please note, that passing "Arch::Name" object as the parameter does not construct a new instance, but returns this passed object. Use clone instead if you want to clone the passed object. Or explicitly call set.
my $name = Arch::Name->new("user@host--arch/cat--felix--1.2.3");
$name->apply([ '1.2.4', 'leo' ]); # ok, new branch-version
or:
$name->apply({ branch => 'leo', version => '1.2.4' }); # ditto
or:
$name->apply([ 'panther' ]); # error, invalid version
or:
$name->apply([ undef, 'panther' ]); # ok, it is branch now
or:
$name->apply({ category => 'dog' }); # ok, it is category now
or:
$name->apply({ branch => 'leo' }); # ok, == [undef, 'leo']
or:
$name->apply({ version => undef }); # ok, it is branch now
or:
$name->apply({ revision => 'patch-6' }); # ok, it is revision now
or:
$name->apply([], 'patch-6'); # ditto
or:
$name->apply([ '1.2.4' ], 'patch-6'); # ditto with new version
or:
$branch->apply([], '0', 'base-0'); # ok, go import revision
or:
$branch->apply('0', 'base-0') ; # ditto
Returns array or arrayref depending on context.
Returns hash or hashref depending on context.
This last error string is class global and it is (un)set on every set or apply method.
If stringify-flag is set, then return the same as a text, i.e. one of the values: "none", "archive", "category", "branch", "version", "revision".
If the original object contains less components than requested, then undef if returned.
If elem is given that is one of the strings "archive", "category", "branch", "version" and "revision", then return true if the object represents the given element (for example, category), and false otherwise.
If elem is given that is one of the strings "archive+", "category+", "branch+", "version+" and "revision+", then return true if the object represents at least the given element, and false otherwise.
The following operators are overloaded:
"" # to_string
0+ # level
bool # is_valid
= # clone
+ # child
- # parent
+= # go_down
-= # go_up
No known bugs.
"man perl | grep more"
Mikhael Goikhman (migo@homemail.com--Perl-GPL/arch-perl--devel).
For more information, see tla, Arch::Session, Arch::Library, Arch::Tree.
| 2005-01-09 | perl v5.20.2 |