def query_package(module, pkgin_path, name):
    """Search for the package by name.

    Possible return values:
    * "present"  - installed, no upgrade needed
    * "outdated" - installed, but can be upgraded
    * False      - not installed or not found
    """

    # Use "pkgin search" to find the package. The regular expression will
    # only match on the complete name.
    rc, out, err = module.run_command("%s search \"^%s$\"" % (pkgin_path, name))

    # rc will not be 0 unless the search was a success
    if rc == 0:

        # Get first line
        line = out.split('\n')[0]

        # Break up line at spaces.  The first part will be the package with its
        # version (e.g. 'gcc47-libs-4.7.2nb4'), and the second will be the state
        # of the package:
        #     ''  - not installed
        #     '<' - installed but out of date
        #     '=' - installed and up to date
        #     '>' - installed but newer than the repository version
        pkgname_with_version, raw_state = out.split(' ')[0:2]

        # Strip version
        # (results in sth like 'gcc47-libs')
        pkgname_without_version = '-'.join(pkgname_with_version.split('-')[:-1])

        if name != pkgname_without_version:
            return False
        # no fall-through

        # The package was found; now return its state
        if raw_state == '<':
            return 'outdated'
        elif raw_state == '=' or raw_state == '>':
            return 'present'
        else:
            return False