# File lib/puppet/provider/package/portupgrade.rb, line 33
33:     def self.instances
34:       Puppet.debug "portupgrade.rb Building packages list from installed ports"
35: 
36:       # regex to match output from pkg_info
37:       regex = %r{^(\S+)-([^-\s]+):(\S+)$}
38:       # Corresponding field names
39:       fields = [:portname, :ensure, :portorigin]
40:       # define Temporary hash used, packages array of hashes
41:       hash = Hash.new
42:       packages = []
43: 
44:       # exec command
45:       cmdline = ["-aoQ"]
46:       begin
47:         output = portinfo(*cmdline)
48:         rescue Puppet::ExecutionFailure
49:           raise Puppet::Error.new(output)
50:           return nil
51:         end
52: 
53:         # split output and match it and populate temp hash
54:         output.split("\n").each { |data|
55:         #         reset hash to nil for each line
56:         hash.clear
57:         if match = regex.match(data)
58:         #                 Output matched regex
59:         fields.zip(match.captures) { |field, value|
60:           hash[field] = value
61:             }
62: 
63:             # populate the actual :name field from the :portorigin
64:             # Set :provider to this object name
65:             hash[:name] = hash[:portorigin]
66:             hash[:provider] = self.name
67: 
68:             # Add to the full packages listing
69:             packages << new(hash)
70: 
71:             else
72:             #         unrecognised output from pkg_info
73:             Puppet.debug "portupgrade.Instances() - unable to match output: #{data}"
74:             end
75:         }
76: 
77:         # return the packages array of hashes
78:         return packages
79: 
80:     end