Helix Core is now P4. Product user interfaces will be updated soon. Learn more >>

P4 API for Perl Documentation | 2025.1

# Class P4::Map

## Description

The `P4::Map` class allows users to create and work with P4 Server mappings, without requiring a connection to a P4 Server.

## Class Methods

### $map = new P4::Map( [ array ] ) -> aMap

Constructs a new `P4::Map` object.

### $map->Join( map1, map2 ) -> aMap

Join two `P4::Map` objects and create a third.

The new map is composed of the left-hand side of the first mapping, as joined to the right-hand side of the second mapping. For example:

    # Map depot syntax to client syntax
    $client_map = new P4::Map;
    $client_map->Insert( "//depot/main/...", "//client/..." );

    # Map client syntax to local syntax
    $client_root = new P4::Map;
    $client_root->Insert( "//client/...", "/home/bruno/workspace/..." );

    # Join the previous mappings to map depot syntax to local syntax
    $local_map = P4::Map::Join( $client_map, $client_root );
    $local_path = $local_map->Translate( "//depot/main/www/index.html" );

    # $local_path is now /home/bruno/workspace/www/index.html

## Instance Methods

### $map->Clear() -> undef

Empty a map.

### $map->Count() -> integer

Return the number of entries in a map.

### $map->IsEmpty() -> bool

Test whether a map object is empty.

### $map->Insert( string …​ ) -> undef

Inserts an entry into the map.

May be called with one or two arguments. If called with one argument, the string is assumed to be a string containing either a half-map, or a string containing both halves of the mapping. In this form, mappings with embedded spaces must be quoted. If called with two arguments, each argument is assumed to be half of the mapping, and quotes are optional.

    # called with two arguments:
    $map->Insert( "//depot/main/...", "//client/..." );

    # called with one argument containing both halves of the mapping:
    $map->Insert( "//depot/live/... //client/live/..." );

    # called with one argument containing a half-map:
    # This call produces the mapping "depot/... depot/..."
    $map->Insert( "depot/..." );

### $map->Translate( string, [ bool ] ) -> string

Translate a string through a map, and return the result. If the optional second argument is 1, translate forward, and if it is 0, translate in the reverse direction. By default, translation is in the forward direction.

### $map->Includes( string ) -> bool

Tests whether a path is mapped or not.

    if ( $map->Includes( "//depot/main/..." ) ) {
      ...
    }

### $map->Reverse() -> aMap

Return a new `P4::Map` object with the left and right sides of the mapping swapped. The original object is unchanged.

### $map->Lhs() -> array

Returns the left side of a mapping as an array.

### $map->Rhs() -> array

Returns the right side of a mapping as an array.

### $map->AsArray() -> array

Returns the map as an array.

Your search for returned results